mongo-join在node.js

时间:2016-05-13 07:39:58

标签: node.js mongodb

我正在使用mongo-join连接node.js中的两个集合。下面的代码显示了查询但它没有加入两个集合。有人请帮助我。

something.js

var client = new Db(config.dbname, new Server(config.host, config.port1));
            client.open(function(err, client) {
                client.collection('proInfo', function(err, proInfo) {
                    proInfo.find({}, function(err, cursor) {
                        var join = new Join(client).on({
                            field: '_id', // <- field in proInfo doc 
                            to: 'purchasedItemId',// <- field in purchased doc. treated as ObjectID automatically. 
                            from: 'purchased'  // <- collection name for purchased doc 
                        });   
                        join.toArray(cursor, function(err, joinedDocs) {
                        // handle array of joined documents here 
                        console.log(joinedDocs);
                        });


                    });
                });  
            });

两个集合,

proInfo集合

{ "_id"▼: ObjectId("573337d73e102e40365bb5db"), "Product_Name": "KRISONS BLUETOOTH 5.1 MULTIMEDIA SPEAKER HOME THEATER SYSTEM", "Brand": "Krisons", "Color": "", "Image": "http://ecx.images-amazon.com/images/I/41H6cuSsemL._SY300_QL70_.jpg", "Price": "2,690.00", "Rating": "3.6 out of 5 stars", "Description": "Krisons 5.1 Speaker System has various input sources like Bluetooth, USB ,FM Radio , AUX-IN and SD Card reader and is compatible with your Mobile Phon [...]", "Category": "Electronics", "Url": "http://www.amazon.in/KRISONS-BLUETOOTH-MULTIMEDIA-SPEAKER-THEATER/dp/B019FR8ZYQ/ref=sr_1_1?s=electronics&ie=UTF8&qid=1462974388&sr=1-1", "userId": ObjectId("570dec75cf30bf4c09679deb"), "purchased": "yes", "contributed": "" }

购买了藏品

{ "_id": ObjectId("5734534d242223b40d9bbe3c"), "quantity": "2", "store": "amazon", "purchasedPerson": "vinay", "email": "vinay@gmail.com", "message": "I purchased this item for you", "terms": "yes", "purchasedItemID": "573337d73e102e40365bb5db", "purchasedDate": "2016-05-12T09:54:37.916Z", "ownerId": "570dec75cf30bf4c09679deb" }

0 个答案:

没有答案