aggregation framework - mongodb setdifference between collection -


i have following 2 collection in mongodb

db.test.insert({"name":"a","keyid":1,"description":"test"}) db.test.insert({"name":"a","keyid":2,"description":"test"}) db.test.insert({"name":"a","keyid":3,"description":"test"}) db.test.insert({"name":"a","keyid":5,"description":"test"}) db.test.insert({"name":"a","keyid":6,"description":"test"}) db.test.insert({"name":"b","keyid":3,"description":"test"}) db.test.insert({"name":"b","keyid":4,"description":"test"})   db.test1.insert({"name":"a","keyid":1,"description":"test"}) db.test1.insert({"name":"a","keyid":2,"description":"test"}) db.test1.insert({"name":"a","keyid":8,"description":"test"}) db.test1.insert({"name":"a","keyid":5,"description":"test"}) db.test1.insert({"name":"a","keyid":6,"description":"test"}) 

i insert documents test test1 key id , name not present in test1 in case

db.test1.insert({"name":"a","keyid":3,"description":"test"}) db.test1.insert({"name":"b","keyid":3,"description":"test"}) db.test1.insert({"name":"b","keyid":4,"description":"test"}) 

and similary insert documents test1 test key id , name not present in test in case

 db.test.insert({"name":"a","keyid":8,"description":"test"}) 

basically try perform setdifference between 2 collection

currently doing

db.test.aggregate([    {"$group" : {_id : {name:"$name", keyid:"$keyid"}}},     {"$project" : { name:"$_id.name",keyid:"$_id.keyid"}} ], { allowdiskuse: true }) 

and

db.test1.aggregate([    {"$group" : {_id : {name:"$name", keyid:"$keyid"}}},     {"$project" : { name:"$_id.name",keyid:"$_id.keyid"}} ], { allowdiskuse: true }) 

then performing whether output in first aggregation pipeline exist in output of second aggregation pipeline , vice versa .

is there better way of doing using set operation in mongodb.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -