mongodb join-like query with two collections and a where clause

前端 未结 1 1630
北荒
北荒 2021-01-16 16:52

Suppose we have following collections in a database:

db.documents.insert([{\'name\': \'A\'}, {\'name\': \'B\'}, {\'name\': \'C\'}])
db.fragments.insert([{\'v         


        
相关标签:
1条回答
  • 2021-01-16 17:18
    db.fragments.find( { 'doc_name': { $in : ['A' , 'B'] } } ); 
    

    Execute this commands in 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 } } ); 
    
    0 讨论(0)
提交回复
热议问题