Every line of 'mongoose updatemany' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
349 updateMany(query: ObjectLiteral, update: ObjectLiteral, options?: { upsert?: boolean, w?: any, wtimeout?: number, j?: boolean }): Promise { 350 return this.manager.updateMany(this.metadata.tableName, query, update, options); 351 }
358 async updateMany(collectionName: string, query: ObjectLiteral, update: ObjectLiteral, options?: { upsert?: boolean, w?: any, wtimeout?: number, j?: boolean }): Promise { 359 return await this.getCollection(collectionName).updateMany(query, update, options); 360 }
69 async updateMany(query, updates) { 70 const docs = await this.find(query, { fields: { _id: 1 } }); 71 const result = await this.collection.updateMany(query, { 72 $set: Object.assign({}, updates, { 73 updatedAt: new Date().toISOString() 74 }) 75 }); 76 this.loader.clearAll(); 77 const ids = docs.map((d) => d._id); 78 this.findManyById(ids); 79 ids.forEach(async (id) => { 80 this.pubsub.publish( 81 `${this.typeSingular}Updated`, 82 { [`${this.typeSingular}Updated`]: await this.findOneById(id) } 83 ); 84 }); 85 return result; 86 }
144 async updateMany(query: object, data: Partial): Promise { 145 await this.model.sync(); 146 this.removeIdAndTimeStamps(data); 147 148 await this.model.update(data, { 149 where: query, 150 }); 151 }
94 findOneAndUpdate(collection, query, values, options) { 95 var that = this; 96 query = castQueryIds(query); 97 if (!options) { 98 options = {}; 99 } 100 101 // Always return the updated object 102 options.returnOriginal = false; 103 104 return new Promise(function(resolve, reject) { 105 var db = that._mongo.collection(collection); 106 107 var update = values; 108 if (options.upsert) { 109 update = { $setOnInsert: update }; 110 } else { 111 update = { $set: update }; 112 } 113 114 db.findOneAndUpdate(query, update, options, function(error, result) { 115 if (error) return reject(error); 116 resolve(result.value); 117 }); 118 }); 119 }
128 updateOne(query, update) { 129 return this._mongoCollection.updateOne(query, update); 130 }
18 update (query, data) { 19 return this.table.updateOne(query, { 20 $set: data 21 }); 22 }
30 async update( 31 entry: IdentifyEntry, 32 fields: string[] = this.defaultQueryFields 33 ): Promise { 34 const instance = await this.model 35 .findOneAndUpdate( 36 { _id: entry.id }, 37 { $set: entry }, 38 { upsert: true, fields: this.getFields(fields), new: true } 39 ) 40 .exec(); 41 return instance; 42 }
209 deleteMany (query) { 210 let args = this.getBaseArgs() 211 args.query = query 212 args.singleDoc = false 213 return this.db.client.executePipeline([ 214 { 215 'service': this.db.service, 216 'action': 'delete', 217 'args': args 218 } 219 ]) 220 }
102 updateOne(query, update) { 103 return this.constructor._getCollection(this.collection) 104 .then(function(db) { 105 return new Promise((resolve, reject) => { 106 db.update(query, update, { multi: false }, function (err, numAffected) { 107 if(err) { 108 reject(err); 109 } 110 else { 111 resolve(numAffected); 112 } 113 }); 114 }); 115 }); 116 }