Sign In Register

How can we help you today?

Start a new topic
Answered

Using $in on $oid

Hello, 


It is possible In MongoDb to make query:

collection.find({ "_id.$oid": { $in: [ id1, ... , idn ] } });


Is there a way to make similar query on system collection Player in order to avoid multiple mongodb access with findOne( { _id: { $oid: id} }) for id=id1, ... , idn ?


Best Regards,

Sasha



Best Answer

Hi Sasha,


This is possible, but the array elements you're checking against need to be objectIds. This syntax should work:


collection.find({"_id":{"$in":[{"$oid":id1},{"$oid":id2}......,{"$oid":idn]}});


Try this out and let us know how it works for you.


Regards,

Vinnie

1 Comment

Answer

Hi Sasha,


This is possible, but the array elements you're checking against need to be objectIds. This syntax should work:


collection.find({"_id":{"$in":[{"$oid":id1},{"$oid":id2}......,{"$oid":idn]}});


Try this out and let us know how it works for you.


Regards,

Vinnie

Login to post a comment