In mongodb, I can do this by the following query:
find(
{ _id : { $in : [ ObjectId('5275c6721a88939923c3ea54'), ObjectId('5275c6721a88939923c3ea55'), ObjectId('5275c6721a88939923c3ea56'), ObjectId('5275c6721a88939923c3ea57'), ObjectId('5275c6721a88939923c3ea58') ] } }
)
But how can we do the same using Jongo code?
I know we can find one document via:
db.getCollection("mongoEg").findOne(Oid.withOid("5194d46bdda2de09c656b64b")).as(MongoTest.class);
But how to get more than one documents in one query via Jongo?
I see two options to achieve a find on multiple ids:
findOne
offers a convenience method with anObjectId
and, if you use an annotatedString
instead of anObjectId
, theOid.withOid
method transforms yourString
into anObjectId
.But, in the end, this convenience method input is transformed into a regular stringified query. So if the convenience don't fit your need, try a query instead.