[SERVER-230] $in operator to recognise and obey DBRefs Created: 12/Aug/09  Updated: 06/Dec/22  Resolved: 19/May/17

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 0.9.7
Fix Version/s: None

Type: Improvement Priority: Trivial - P5
Reporter: Phillip Oldham Assignee: Backlog - Query Team (Inactive)
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query
Participants:

 Description   

It would be very useful if the $in operator could recognise and obey DBRefs when querying. For example:

> // excerpt of Account document
> { users : [ { "$ref": "users", "$id": 11 }, { "$ref": "users", "$id": 20 }, { "$ref": "customers", "$id": 7 } ] }
> // get account
> var account = db.accounts.findOne( ... )
> // get all users at once
> db.users.find( { _id : { $in : account.users });

Which returns back {user 11} and {user 20}, but not {user 7} because it's actually a "customer" collection reference.



 Comments   
Comment by sandstrom [ 03/Sep/09 ]

May be wrong, but I think that the db references are handled only at the driver level (which I think is good).

This should work if evaluated server-side. Otherwise you can rewrite the map in the language you use.
db.users.find( { _id: { $in : account.users.map(function(e)

{return e.$id; }

) } })

Generated at Thu Feb 08 02:53:27 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.