Reputation: 33
db.a.find({ "id" : { "$in" : db.b.distinct("id") } })
This nested query is workable via shell client.
I'd like to implement it via Java code, but I don't know how. Could anyone please help me?
Upvotes: 0
Views: 45
Reputation: 26
Try this
MongoCollection collectionA = database.getCollection("a");
MongoCollection collectionB = database.getCollection("b");
Bson filter1 = new Document("$in", collectionB.distinct("id"));
Bson filter2 = new Document("id",filter1);
List all = collectionA .find(filter2).into(new ArrayList ());
Upvotes: 1