Best way to merge two mongoDB collections into one -
i have 2 mongodb collections named users , users_custom. example: users collection looks like:
{ "_id" : objectid("53ac64d445fa47e97a5f3b50"), "user_id" : "1", "name" : "mr. a", "phone" : "12345" } { "_id" : objectid("53ac64e145fa47e97a5f3b53"), "user_id" : "2", "name" : "mr. b", "phone" : "23456" } users_custom collection looks like:
{ "_id" : objectid("53ac64d445fa47e97a5f3b32"), "user_id" : "1", "name" : "mr. modified", "email" : "someone@gmail.com" } { "_id" : objectid("53ac64e145fa47e97a5f3b232"), "user_id" : "2", "name" : "mr. b", "address" : "some address" } i want merge users_custom collection on users collection users_final collection. way looks like:
{ "_id" : objectid("53ac64d445fa47e97a5f3b32"), "user_id" : "1", "name" : "mr. modified", "phone" : "12345" "email" : "someone@gmail.com" } { "_id" : objectid("53ac64e145fa47e97a5f3b232"), "user_id" : "2", "name" : "mr. b", "phone" : "23456" "address" : "some address" } any thought or illustration code appreciated. in advance.
what you're trying bring together 2 collections. mongodb doesn't back upwards joins natively though, through map cut down framework can implement bring together function. may take while , should done offline, not real-time query.
these questions/articles should provide guidance:
mongodb: combine info multiple collections in one..how?
merging 2 collections in mongodb
http://tebros.com/2011/07/using-mongodb-mapreduce-to-join-2-collections/
mongodb
No comments:
Post a Comment