How can use mongodb and node js with complicated query

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How can use mongodb and node js with complicated query



I want in node js use mongodb.
I can insert,update ,.... in mongo with node. for example i can select with find but i can not Input the result of one query1 for query2.



Click here to see image




1 Answer
1



You can first get all the records from the collection that match the where query then loop over to those records to update only those resultant records that have c=4:


where


c=4


MyCollectionName.find(a:$gt: 4, b:$gt: 3, function findResult(err, findResult)
if (err)
console.log('Error on find');
return;

findResult.forEach(function (result)
if(result.c === 4)
result.c = 5;
result.save(function saveResult(err, savedResult)
if (err)
console.log('Error on save');
return;

console.log('Updated...');
return;
);

);
);



Where, MyCollectionName is the mongoose model for the collection you wish to query.


MyCollectionName





can we do that without forEach and for , while ,....?
– Moh_beh
Aug 7 at 12:13






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

make 2 or more post in bootsrap

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3

Firebase Auth - with Email and Password - Check user already registered