Reputation: 2094
I've got collection like this:
{
"_id" : ObjectId("546089aaf83a94de268a35c3"),
"parent" : {
"$ref" : "someRef",
"$id" : ObjectId("546089aaf83a94de268a35c3"),
"$db" : "someDB",
}
}
How can I look for all the record where _id is equal to parent.id?
Tried find({"parent.$id": "_id"})
but obviously that can't be it
Upvotes: 2
Views: 263
Reputation: 3010
The parent
here holds the database reference. Thus we need to call the getter method of the reference to get its object ID.
The following query can get us the expected output:
db.collection.find({
$where: function(){
return this._id.toString() == this.parent.getId().toString();
}
}).pretty()
Upvotes: 2