0

Suppose I have two collections in Mongodb say Col_1 and Col_2. Format for Col_1:

{
"_id":"",
"Field_1":"abc",
"Field_2":"color"
},
{

"_id":"",
"Field_1":"red"
"Field_2":"fruits"
}

And the format of Col_2 is: {

"_id":"",
"Field_1":"xyz abc orange red",
"Field_2":"799842",
"Field_3":""
}

{

"_id":"",
"Field_1":"xyz abc orange red",
"Field_2":"4743893",
"Field_3":""

}

I want to compare the field1 of Col_1 with the field1 of Col_2 and update the Field3 of Col_2 with the field2 of Col_1.

Suppose if we apply the find command and it returns with the matched documents I want to update those.Can I perform this on shell or I need to use some programming language?

nik
  • 13
  • 6
  • MongoDB never support joins like `sql` so this not possible, either you should change your collection's structure. for more check this http://stackoverflow.com/questions/4067197/mongodb-and-joins – Neo-coder Apr 07 '15 at 07:56
  • So how can I implement this,is there any alternative? – nik Apr 07 '15 at 08:01
  • there was no alternative, you should follow this http://stackoverflow.com/questions/5681851/mongodb-combine-data-from-multiple-collections-into-one-how o.w. change your collections, create single collections instead of multiple collections. – Neo-coder Apr 07 '15 at 08:05
  • ok.thanx If i put this in a single collection and then with a single query I would be able to find and update? – nik Apr 07 '15 at 08:29
  • yes, if you have any problem in find and updating then you should post questions here. All are here willing to help each other :) – Neo-coder Apr 07 '15 at 08:32
  • @yogesh should I edit my question or post a new question? – nik Apr 07 '15 at 08:48
  • Better way to post new questions with new collections and your problem. – Neo-coder Apr 07 '15 at 08:49
  • @yogesh can you help here - http://stackoverflow.com/questions/29488115/how-to-perform-matching-inside-a-collection-in-mongodb-and-perform-updation-in-t – nik Apr 07 '15 at 09:23

0 Answers0