This is function that tries to update the code matching by its value
the res collection
as having the code of Marque
it will be compared with doc.Marque
if it is the case it will be replaced by the value of the marque
.
This code is working perfectly in mongoDB CLI
, but as i am working with GO
.
I tried to convert it into mgo
as you may see below but it is not working , i did not find the foreach function in mgo
, is there something to be replaced with in this case ? thanks for the help
db.res.find().forEach(function(doc){
var v = db.brands.findOne({code: doc.Marque});
if(v){
db.res.update({"Marque": doc.Marque},
{$set: {"Marque":v.value}}, {multi: true});
}
});
Here is what i tried :
result:=Results{}
pipe:=res.find(bson.M{}).Iter()
for pipe.Next(&result) {
brands:=brands.findOne({code: doc.Marque});
if(v){
pipe.update({"Marque": doc.Marque},
{$set: {"Marque": v.value}}, {multi: true});
}
}