MongoDB Federated Query
2012-04-15 16:32:44| Category: MongoDB | Tags:mongodb mongodb Federated Query | Report | Font size Big medium small subscription
1. Simple manual correlationFirst, the results are queried and put into a variable, and then queryu = Db.user.findOne ({author: "Wangwenlong"});For (var p = db.postings.find ({author:u.author});p. Hasnext;) {Printjson (P.next (). title); }2, Dbref Way AssociationExample:Step 1 Get current user informationDb.user.insert ({name: "Wangwenlong"})u1 = Db.user.find ({name: "Wangwenlong"}) [0]Step 2 post and associateDb.postings.insert ({"title": "Hello mongodb!"},users:[new dbref (' users ', u1._id)])Db.postings.insert ({"title": "Hello china!"},users:[new dbref (' users ', u1._id)])Step 3 Notice the Post tea-axis user informationDb.postings.find ({title: "Hello china!"}) [0].users[0].fetch ()
MongoDB Federated Query