Skip to content

Conversation

@estolfo
Copy link
Contributor

@estolfo estolfo commented Aug 22, 2015

No description provided.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@behackett I'm assuming that if you provide a $query doc in the selector, it'll use that as the selector, not whatever else is in there. I.e., in this case, { a: 1 } is the selector, not { b: 2 }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@behackett If you have a $query in modifiers, does that get used instead of the selector?

for example:
coll.find({ a: 1 }, { :modifiers => { :$query => { b: 2 } } )

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In PyMongo we don't do anything to try to correct that mistake. Since the options in modifiers are added to the criteria after the criteria is changed to {'$query': {'a': 1}} the query ends up being {'$query': {'b': 2}}.

@estolfo estolfo force-pushed the RUBY-1006-query-modifiers branch from fa17f05 to 314e644 Compare August 23, 2015 06:49
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be:

sel = BSON::Document.new(:$query => selector).merge(modifiers)

In order to get the indifferent access provided by a BSON::Document vs. a normal hash, also, the command monitoring spec guarantees the filter will also be a BSON::Document.

@durran
Copy link
Member

durran commented Aug 24, 2015

Line 261 of Mongo::Protocol::Query (https://github.com/mongodb/mongo-ruby-driver/blob/master/lib/mongo/protocol/query.rb#L261) also needs to change in this pull for command monitoring to pass:

document[:filter] = filter[:$query] ? filter[:$query] : filter

@estolfo
Copy link
Contributor Author

estolfo commented Aug 24, 2015

ah, thanks.
I guess also the modifiers document should be initialized as a BSON::Document as well if the user hasn't specified it. Here: https://github.com/mongodb/mongo-ruby-driver/pull/677/files#diff-9da4b67a7dc4cd1487088c3f70d96f10R441

@durran
Copy link
Member

durran commented Aug 24, 2015

Yeah to be on the safe side I would initialize that as a BSON::Document as well.

estolfo added a commit that referenced this pull request Aug 24, 2015
RUBY-1006 Refactor View and Readable to allow for arbtirary query modifiers
@estolfo estolfo merged commit 89755b1 into mongodb:master Aug 24, 2015
@estolfo estolfo deleted the RUBY-1006-query-modifiers branch September 2, 2015 07:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants