I have found two ways of doing an equivalent of SQL in statement in mongodb. One way would be something like:
BasicDBObject inQuery = new BasicDBObject();
List<Integer> list = new ArrayList<Integer>();
list.add(2);
list.add(4);
list.add(5);
inQuery.put("employeeId", new BasicDBObject("$in", list));
DBCursor cursor = collection.find(inQuery);
And the other one, with a filter, would be something like this:
FindIterable<Document> iterable = db.getCollection("coll_name")
.find(in("field_name", values))
My questions are:
- Which way is better?
- Is it better to use filters? What about the performance between doing the query is the first way against using a filter?