I have two collection "Sample" and "Test" which is 300mb and 4GB respectively. When I tried to query the two collection in a single query I used Javascript. But it takes very long time to execute. How to increase the speed of the query? Below is the query.
db.test.find({}).forEach(function(x) {
if (x.a == null) {
print(x)
} else if (x.a != null) {
db.sample.find({}).forEach(function(y) {
if (y._id == x._id && y.c == true) {
print(x)
}
})
}
})
Also will this query make use of Single indexe which is created on "c" and "a" fields.