-
Notifications
You must be signed in to change notification settings - Fork 29
DOCSP-42753: specify query part 1 #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rustagir
merged 6 commits into
mongodb:standardized
from
rustagir:DOCSP-42753-specify-query
Oct 31, 2024
+652
−7
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
# start-simple-field-query | ||
Band.where(name: 'Depeche Mode') | ||
Band.where('name' => 'Depeche Mode') | ||
# end-simple-field-query | ||
|
||
# start-query-api-query | ||
Band.where(founded: {'$gt' => 1980}) | ||
Band.where('founded' => {'$gt' => 1980}) | ||
# end-query-api-query | ||
|
||
# start-symbol-query | ||
Band.where(:founded.gt => 1980) | ||
# end-symbol-query | ||
|
||
# start-defined-field-query | ||
Band.where(founded: '2020') | ||
# end-defined-field-query | ||
|
||
# start-raw-field-query | ||
Band.where(founded: Mongoid::RawValue('2020')) | ||
# end-raw-field-query | ||
|
||
# start-id-field-query | ||
Band.where(id: '5ebdeddfe1b83265a376a760') | ||
# end-id-field-query | ||
|
||
# start-embedded-query | ||
Band.where('manager.name' => 'Smith') | ||
# end-embedded-query | ||
|
||
# start-embedded-ne-query | ||
Band.where(:'manager.name'.ne => 'Smith') | ||
# end-embedded-ne-query | ||
|
||
# start-logical-ops | ||
# Uses "and" to combine criteria | ||
Band.where(label: 'Trust in Trance').and(name: 'Astral Projection') | ||
|
||
# Uses "or" to specify criteria | ||
Band.where(label: 'Trust in Trance').or(Band.where(name: 'Astral Projection')) | ||
|
||
# Uses "not" to specify criteria | ||
Band.not(label: 'Trust in Trance', name: 'Astral Projection') | ||
|
||
# Uses "not" without arguments | ||
Band.not.where(label: 'Trust in Trance', name: 'Astral Projection') | ||
# end-logical-ops | ||
|
||
# start-logical-and-ops | ||
# Conditions passed to separate "and" calls | ||
Band.and(name: 'Sun Kil Moon').and(member_count: 2) | ||
|
||
# Multiple conditions in the same "and" call | ||
Band.and({name: 'Sun Kil Moon'}, {member_count: 2}) | ||
|
||
# Multiple conditions in an array - Deprecates | ||
Band.and([{name: 'Sun Kil Moon'}, {member_count: 2}]) | ||
|
||
# Condition in "where" and a scope | ||
Band.where(name: 'Sun Kil Moon').and(Band.where(member_count: 2)) | ||
|
||
# Condition in "and" and a scope | ||
Band.and({name: 'Sun Kil Moon'}, Band.where(member_count: 2)) | ||
|
||
# Scope as an array element, nested arrays - Deprecated | ||
Band.and([Band.where(name: 'Sun Kil Moon'), [{member_count: 2}]]) | ||
# end-logical-and-ops | ||
|
||
# start-logical-combination-ops | ||
# Combines as "and" | ||
Band.where(name: 'Swans').where(name: 'Feist') | ||
|
||
# Combines as "or" | ||
Band.where(name: 'Swans').or(name: 'Feist') | ||
# end-logical-combination-ops | ||
|
||
# start-logical-combination-ops-2 | ||
# "or" applies to the first condition, and the second is combined | ||
# as "and" | ||
Band.or(name: 'Sun').where(label: 'Trust') | ||
|
||
# Same as previous example - "where" and "and" are aliases | ||
Band.or(name: 'Sun').and(label: 'Trust') | ||
|
||
# Same operator can be stacked any number of times | ||
Band.or(name: 'Sun').or(label: 'Trust') | ||
|
||
# The last label condition is added to the top level as "and" | ||
Band.where(name: 'Sun').or(label: 'Trust').where(label: 'Feist') | ||
# Interpreted query: | ||
# {"$or"=>[{"name"=>"Sun"}, {"label"=>"Trust"}], "label"=>"Feist"} | ||
# end-logical-combination-ops-2 | ||
|
||
# start-not-logical | ||
# "not" negates "where" | ||
Band.not.where(name: 'Best') | ||
|
||
# The second "where" is added as "$and" | ||
Band.not.where(name: 'Best').where(label: /Records/) | ||
|
||
# "not" negates its argument | ||
Band.not(name: 'Best') | ||
# end-not-logical | ||
|
||
# start-not-logical-note | ||
# String negation - uses "$ne" | ||
Band.not.where(name: 'Best') | ||
|
||
# Regex negation - uses "$not" | ||
Band.not.where(name: /Best/) | ||
# end-not-logical-note | ||
|
||
# start-not-behavior | ||
# Simple condition | ||
Band.not(name: /Best/) | ||
|
||
# Complex conditions | ||
Band.where(name: /Best/).not(name: 'Astral Projection') | ||
|
||
# Symbol operator syntax | ||
Band.not(:name.ne => 'Astral Projection') | ||
# end-not-behavior | ||
|
||
# start-incremental-1 | ||
Band.in(name: ['a']).in(name: ['b']) | ||
# Interpreted query: | ||
# {"name"=>{"$in"=>["a"]}, "$and"=>[{"name"=>{"$in"=>["b"]}}]} | ||
# end-incremental-1 | ||
|
||
# start-in-merge | ||
Band.in(name: ['a']).override.in(name: ['b']) | ||
# Interpreted query: | ||
# {"name"=>{"$in"=>["b"]}} | ||
|
||
Band.in(name: ['a', 'b']).intersect.in(name: ['b', 'c']) | ||
# Interpreted query: | ||
# {"name"=>{"$in"=>["b"]}} | ||
|
||
Band.in(name: ['a']).union.in(name: ['b']) | ||
# Interpreted query: | ||
# {"name"=>{"$in"=>["a", "b"]}} | ||
# end-in-merge | ||
|
||
# start-merge-reset | ||
Band.in(name: ['a']).union.ne(name: 'c').in(name: ['b']) | ||
# Interpreted query: | ||
# {"name"=>{"$in"=>["a"], "$ne"=>"c"}, "$and"=>[{"name"=>{"$in"=>["b"]}}]} | ||
# end-merge-reset | ||
|
||
# start-merge-where | ||
Band.in(name: ['a']).union.where(name: {'$in' => 'b'}) | ||
# Interpreted query: | ||
# {"foo"=>{"$in"=>["a"]}, "$and"=>[{"foo"=>{"$in"=>"b"}}]} | ||
# end-merge-where | ||
|
||
# start-range-query | ||
Band.in(year: 1950..1960) | ||
# Interpreted query: | ||
# {"year"=>{"$in"=>[1950, 1951, 1952, 1953, 1954, 1955, 1956, 1957, 1958, 1959, 1960]}} | ||
# end-range-query | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.