10 examples of 'findoneandupdate mongoose' in JavaScript

Every line of 'findoneandupdate mongoose' 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.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
94findOneAndUpdate(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}
25async findOneAndUpdate(id, data) {
26 const query = {_id: ObjectId(id)};
27 const modifier = {$set: data};
28 const options = {returnOriginal: false};
29 const operation = await this.db
30 .collection(this.name)
31 .findOneAndUpdate(query, modifier, options);
32
33 if (!operation.value) {
34 throw new Error('Db findOneAndUpdate error');
35 }
36 return operation.value;
37}
58public findOne(conditions: any) {
59 return (RoomCache.findOne(conditions, {
60 _id: 0,
61 locked: 1,
62 processId: 1,
63 roomId: 1,
64 })) as any as QueryHelpers;
65}
30async 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}
103function update ( data, callback ){
104
105 callback = callback || function(){};
106
107 player.findOneAndUpdate({'info.id': data.info.id}, data, function (error, foundPlayer) {
108
109 if (error){
110 console.log(error);
111 }
112
113 return callback( foundPlayer );
114
115 //console.log(foundPlayer);
116 });
117}
59findOneAndUpdate(criteria: Object, updateDocument: Object, callback?: ResultCallback): FindOneAndUpdateQuery {
60
61 var query = this._createQuery(QueryKind.FindOneAndUpdate);
62 query.criteria = criteria;
63 query.updateDocument = updateDocument;
64 return query.handleCallback(callback);
65}
5findOne () { return this }
128updateOne(query, update) {
129 return this._mongoCollection.updateOne(query, update);
130}
180findOneAndUpdate(table, options, sets, where, callback) {
181 try {
182 checkParams({table, options, sets, where, callback})
183 } catch (err) {
184 return callback(err)
185 }
186 let _options = _.cloneDeep(options)
187 _options.castIds = false
188 this._conn.collection(table).findOneAndUpdate(where, sets, _options,
189 (err, updated_doc) => {
190 return callback(err, updated_doc, null)
191 })
192}
40db.projects.findOne({_id : db.ObjectId(id)}, function onFound(err, docs) {
41 if (err) {
42 throw err;
43 }
44
45 if (!docs) {
46 callback(null);
47 return;
48 }
49 callback(docs.assetFolder);
50});

Related snippets