0
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?

1 Answer 1

1

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 ());

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your quick reply, I will try this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.