I've got 2 collections that are related. Decks and Facts.
Decks looks like this:
{
_id: ObjectId("123456789123456789"),
title: "test deck"
isActive: true
}
A fact looks like this
{
_id: ObjectId("111111324324434"),
deckId: ObjectId("123456789123456789")
title: "test fact"
}
I come from a SQL background so I want to SELECT * FROM facts LEFT JOIN decks ON decks._id = facts.deckId WHERE deck.isActive = true
The only way I could figure this out was via a micro script.
var deckIds = db.decks.find({isActive: false}, {_id: true}).toArray().map(function(item) {
return item._id;
});
db.facts.find({deckId: {$in: deckIds}});
Is this the best way to do this? Is there a more performant way to do this all in Mongo? I looked at map-reduce but I can't figure out how to do this there and it seemed like way more code. What I want to do in the end is delete the facts that have deck.isActive = false.