Answer the question
In order to leave comments, you need to log in
How to find out if all documents are updated using bulk.execute()?
How can I find out if all documents are up to date?
I am updating the list of documents and there are suspicions that not everything is updated, although I may be wrong.
Here is an example script
const makeRequest = async () => {
const documents = await getDocuments()
return await updateDocumentsBulk(documents), process.exit()
}
return makeRequest().catch(e => { return console.log(e), process.exit() })
function getDocuments(request) {
return Coll_1.aggregate([
{
$match: {} // условие запроса
}, {
$project: {
_id: 1,
count: 1,
pageUrl: 1
}
}, {
$group: {
_id: "$pageUrl",
count: {
$sum: "$count"
}
}
}
])
}
function updateDocumentsBulk(request) {
return bulk = Coll_2.collection.initializeOrderedBulkOp()
, Promise.all(request.map(async e => {
return href = e._id.replace(regex, "$1"), ! /\//.test(href) && bulk.find( { url: href } ).updateOne({ $inc: { "stats.view": e.count } })
})).then(e => {
return e.length && bulk.execute()
})
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question