[SERVER-12199] Add an operator that matches an entire document Created: 24/Dec/13 Updated: 06/Dec/22 |
|
| Status: | Backlog |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Minor - P4 |
| Reporter: | Richard Kreuter (Inactive) | Assignee: | Backlog - Query Optimization |
| Resolution: | Unresolved | Votes: | 1 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Assigned Teams: |
Query Optimization
|
||||||||
| Participants: | |||||||||
| Description |
|
Problem: it's occasionally desirable to be able to specify query that matches a whole document, but the query language doesn't support it (anyway, I can't think of one). Proposal: add a query operator that matches if and only if a document has all the fields and no extra ones. For example, it might look like this:
This would match only documents having the fields "_id", "a", and "b", but no other fields; and presumably it would match only if the document had those three fields in that order. Note that this would make certain updates easier to express, e.g., for the update-if-current idiom. |
| Comments |
| Comment by Asya Kamsky [ 21/Jul/17 ] | |||||
|
Noting here that this is possible using aggregation by comparing "$$ROOT" and specified object. Similar to a workaround described in SERVER-30197:
| |||||
| Comment by Karolin Varner [ 18/Jul/17 ] | |||||
|
@David: Awesome. Thanks! | |||||
| Comment by David Storch [ 18/Jul/17 ] | |||||
|
karo, assuming that you do not consider the ordering of the fields significant, this will be possible to express using JSON Schema. We are currently working on adding support for a $jsonSchema operator in the match language under | |||||
| Comment by Karolin Varner [ 17/Jul/17 ] | |||||
|
If I am not mistaken it is still not possible to express this. For arrays we can use $size, but for objects there is no way to ensure that there are no extra values? |