import { MongoClient } from 'mongodb'
const client = new MongoClient('mongodb:)
await client.connect()
const db = client.db('test')
const insertResult = await db.collection('test').insertOne({ arr: [{ _id: 1, isAdmin: true }, { _id: 2, isAdmin: false }] })
const doc = await db.collection('test').findOne({ _id: insertResult.insertedId })
console.log('before bulk update', doc)
const bulkUpdate = db.collection('test').initializeUnorderedBulkOp()
bulkUpdate.find({ _id: doc.insertedId }).updateOne({ $pull: { arr: { _id: 1 } } })
if (bulkUpdate.length > 0) {
console.log('executing bulk update')
await bulkUpdate.execute()
}
const updatedDoc = await db.collection('test').findOne({ _id: doc._id })
console.log('after bulk update', updatedDoc)
await db.collection('test').deleteOne({ _id: doc._id })