You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MongoDB uses BSON for storing its documents [*1]. BSON in contrast with JSON has ordered key/value pairs [*2]. I think this means we should use OrderedDictionary for our documents (instead of Dictionary). This is also mentioned in #61 and does not only refer to the data we store, but also things like commands and the sort order which is specified by a document [*3] when querying. For example, the current MongoQuery implementation uses a Dictionary which could give incorrect results (even if provided as an OrderedDictionary it still replaces it with a Dictionary [*4]):
MongoQuery >> #order: anArrayOfAssociation
order := anArrayOfAssociation asDictionary.
Any thoughts on how to tackle this?
We could simply replace all existing references to Dictionary (or #asDictionary) with the OrderedDictionary within MongoTalk, but I'm not sure if it would break existing code (elsewhere). From the Voyage-Mongo extension there is also reference to Dictionary which might need to be replaced as well. Maybe in other places too.
Another solution would be to add #asDictionary as an extension method to OrderedDictionary (and simply answer self) to prevent a correctly provided document from being changed. Then it is the user's responsibility to provide the correct documents. But would that break other (non Mongo-related) behaviour?
The 'in-between' solution could be to implement an #asBSONDocument behaviour and use it consistently within MongoTalk. Allowing both Dictionary and Array (of Associations) instances to be converted to an OrderedDictionary instance.
MongoDB uses BSON for storing its documents [*1]. BSON in contrast with JSON has ordered key/value pairs [*2]. I think this means we should use
OrderedDictionary
for our documents (instead ofDictionary
). This is also mentioned in #61 and does not only refer to the data we store, but also things like commands and the sort order which is specified by a document [*3] when querying. For example, the currentMongoQuery
implementation uses aDictionary
which could give incorrect results (even if provided as anOrderedDictionary
it still replaces it with aDictionary
[*4]):Any thoughts on how to tackle this?
We could simply replace all existing references to
Dictionary
(or#asDictionary
) with theOrderedDictionary
within MongoTalk, but I'm not sure if it would break existing code (elsewhere). From the Voyage-Mongo extension there is also reference toDictionary
which might need to be replaced as well. Maybe in other places too.Another solution would be to add
#asDictionary
as an extension method toOrderedDictionary
(and simply answerself
) to prevent a correctly provided document from being changed. Then it is the user's responsibility to provide the correct documents. But would that break other (non Mongo-related) behaviour?The 'in-between' solution could be to implement an
#asBSONDocument
behaviour and use it consistently within MongoTalk. Allowing bothDictionary
andArray
(of Associations) instances to be converted to anOrderedDictionary
instance.Interested in your thoughts about this.
[*1] https://docs.mongodb.com/manual/core/document/
[*2] https://bsonspec.org/spec.html (see first paragraph
BSON is a binary format in which zero or more ordered key/value pairs are stored as a single entity.
)[*3] https://docs.mongodb.com/manual/reference/method/cursor.sort/
[*4] It is not fully clear whether
#order:
expects anArray
or aDictionary
, since the following method (one of two users of the setter) seems to specify it is aDictionary
:The text was updated successfully, but these errors were encountered: