MongoDB update using limit and skip

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



MongoDB update using limit and skip



In Mongoose, I would need to do the following in the quickest possible way:



what do you suggest?





do you want to update a field in all the found records with same value?
– Yogesh.Kathayat
Aug 13 at 9:14





Yes, I update them with the same value
– Ehsan
Aug 13 at 9:18




1 Answer
1



you can get records and then get id's of all the records into one array and then
update them using $in


$in


async function someAsyncFunction()

let foundData= await collection.find(query).skip().limit();
let IDs=;

foundData.forEach(element=>
IDs.push(element._id);
);

return Collection.update(
_id: $in: IDs,
$set: "fieldToUpdate": "value",
multi: true
);






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

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

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS