[SERVER-30196] $size for objects (implementing update-if-current/atomics) Created: 17/Jul/17 Updated: 24/Aug/17 Resolved: 28/Jul/17 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Karolin Varner | Assignee: | Asya Kamsky |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Participants: | |||||||||
| Description |
|
It would be nice if the $size operator supported objects! This would specifically be handy for implementing the update-if-current idom; e.g. one could match the following subdocument exactly and order-indipentantly: Document:
Query:
|
| Comments |
| Comment by Asya Kamsky [ 28/Jul/17 ] | |||||||||||||||||||||
|
Because it will be possible to do this in several different ways in the upcoming 3.6 release, either via aggregation expression or via $jsonSchema operator, it's unlikely we would also add a top level operator for number of fields in an object, so I'm closing this ticket as Won't Fix. | |||||||||||||||||||||
| Comment by Asya Kamsky [ 21/Jul/17 ] | |||||||||||||||||||||
|
Note that this can also be achieved via aggregation expressions:
| |||||||||||||||||||||
| Comment by David Storch [ 21/Jul/17 ] | |||||||||||||||||||||
|
Hi karo, this looks like something that can be expressed with JSON Schema, albeit in a somewhat wordy fashion. The work to add support for JSON Schema is being tracked by
However, I think it still makes sense to leave this feature request open, since we may still want to add querying on the number of properties in an object as a first-class citizen of the MongoDB query language. Best, | |||||||||||||||||||||
| Comment by Karolin Varner [ 20/Jul/17 ] | |||||||||||||||||||||
|
Hi Mark, That's quite all right, thanks for responding a second time! This is ticket 30196 so I guess you have a fairly intense influx of tickets that need quick closing Best, | |||||||||||||||||||||
| Comment by Mark Agarunov [ 20/Jul/17 ] | |||||||||||||||||||||
|
Hello karo, My apologies, I initially misunderstood your request. To clarify the feature you're requesting, my understanding is that you are proposing an operator that will allow for counting the number of fields in an object, regardless of their values or order. Please let me know if that describes the behavior you are requesting correctly. Thanks, | |||||||||||||||||||||
| Comment by Karolin Varner [ 20/Jul/17 ] | |||||||||||||||||||||
|
@Mark This was a feature request btw. I tested and I was pretty sure that the functionality I am suggesting in here does not exist in mongodb yet, which is why I didn't post it on stackoverflow. | |||||||||||||||||||||
| Comment by Karolin Varner [ 20/Jul/17 ] | |||||||||||||||||||||
|
Well, I need to be able to use it in a query if I want to use it as a filter clause in update() (to implement update-if-current). | |||||||||||||||||||||
| Comment by Mark Agarunov [ 19/Jul/17 ] | |||||||||||||||||||||
|
Hello karo, Thank you for the report. Looking over the examples you've provided, the Object.bsonsize function may work for your use case. For example:
Please note that SERVER project is for reporting bugs or feature suggestions for the MongoDB server. For MongoDB-related support discussion please post on the mongodb-user group or Stack Overflow with the mongodb tag. A question like this involving more discussion would be best posted on the mongodb-user group. Thanks, |