db.colors.insert({
"_id" : 12,
"records" : [{
"blue" : 1,
"green" : 22,
"yellow" : 26
}, {
"blue" : 1,
"green" : 22,
"yellow" : 44
}, {
"blue" : 1,
"green" : 28,
"yellow" : 26
}, {
"blue" : 1,
"green" : 33,
"yellow" : 26
}]
})
db.colors.find({ "records.blue" : 1}).forEach(function(x) { printjson(x.records) })
db.colors.find({ "records.blue" : 1}).forEach(function(x) {
match = false;
for(i=0 ; i< x.records.length ; i++)
{
var blueValue = x.records[i].blue;
//print(blueValue);
if(blueValue==1) {
print("green--yellow value : " + x.records[i].green +"--"+ x.records[i].yellow);
match = true;
x.records[i].green = 4444;
}
}
if(match==true){
print("true");
db.colors.update( { _id: x._id }, x );
}
});
Comments
Post a Comment