Мне известно о setDefaultsOnInsert
, но я не могу понять, как включить эту опцию в запрос.
Я не вижу ни одного параметра для параметров в документации, поэтому я не уверено том, как включить это в мой запрос.
Любая помощь будет оценена.
let bulk = Notification.collection.initializeUnorderedBulkOp()
activity.notify.forEach( user_id => {
query = { 'notification._id': activity._id, user_id, type: "replied to an idea you're subscribed to" }
update = { $set: { notification: activity }, $addToSet: { user_details: user_data } }
options = { setDefaultsOnInsert: true }
bulk.find( query ).upsert().update( update, options )
} )