I have a JUnit rule
called as MongoRule
looks like
public class MongoRule extends ExternalResource {
private static final Lo
You are now doing the equivalent of :
db.col.find({$in:[{Id:id1}, {Id:id2}, ..., {Id:idN}]})
Which is not a valid query since you're not specifying what field to $in on. I'm assuming you want :
db.col.find({Id:{$in:[id1, id2, ..., idN]}})
Change your query construction code accordingly and you should be fine.
EDIT: Adding correct code :
public static void getDocuments(List<Integer> documentIds) {
BasicDBList docIds = new BasicDBList();
docIds.addAll(documentIds)
DBObject inClause = new BasicDBObject("$in", docIds);
DBObject query = new BasicDBObject("Id", inClause);
DBCursor dbCursor = mongoRule.getDatabase().getCollection("mycollection").find(query);
System.out.println(dbCursor == null);
if (dbCursor != null) {
while (dbCursor.hasNext()) {
System.out.println("object - " + dbCursor.next());
}
}
}
Please note that this assumes "Id" is something other than "_id"