Suppose we have following collections in a database:
db.documents.insert([{\'name\': \'A\'}, {\'name\': \'B\'}, {\'name\': \'C\'}]) db.fragments.insert([{\'v
db.fragments.find( { 'doc_name': { $in : ['A' , 'B'] } } );
Execute this commands in mongo:
mongo
var f = db.documents.find().limit(2) , n = []; for (var i = 0; i < f.length(); i++) n.push(f[i]['name']); db.fragments.find( { 'doc_name': { $in : n } } );