0

I have two collections.

I am using MongoDB version 3.4.

Collection 1 called Results

Collection 2 called Code_Value

Here i have to update automatically the code in the result using the Code_value Collections

The results is like:

{
_id: ObjectId(xxxxxxx)
name:"Mike"
job:"3"
salary:"4"
}

{
_id: ObjectId(xxxxxxx)
name:"Joe"
job:"1"
salary:"2"
}

the Code_value is like:

{ 
 "Job":[ 
        {"code":"1" , "value":"IT"}
        {"code":"2" , "value":"Doctor"}
        {"code":"3" , "value":"Developer"}

      ]

 "Salary":[ 
        {"code":"1" , "value":"900000"}
        {"code":"2" , "value":"100000"}
        {"code":"3" , "value":"200000"}
        {"code":"4" , "value":"300000"}

      ]

}

I'd like to have a mapping code value on the results as the following:

 {
 _id: ObjectId(xxxxxxx)
 name:"Mike"
 job:"Developer"
 salary:"300000"
 }

 {
_id: ObjectId(xxxxxxx)
 name:"Joe"
 job:"IT"
 salary:"100000"
 }

here is the query made as function

 results.find().foreach(cursor){
 v=Code_value.find(cursor,code)
 if(v){
 results.update(job,v.value)
                               }
Medo
  • 83
  • 1
  • 8
  • You have to use [MongoDB aggregation](https://docs.mongodb.com/manual/aggregation/) for such query, and use the community supported driver [`github.com/globalsign/mgo`](https://github.com/globalsign/mgo). – icza May 23 '18 at 10:51
  • @Neil Lunn i edited the question thanks for the notice maybe i did not explain well the problem , please could you see it again thanks – Medo May 23 '18 at 13:29
  • @icza thanks i changed to it , but the problem of query still not working , could you please guide or give a help please ? – Medo May 23 '18 at 13:30

0 Answers0