Every line of 'mongoose update nested array' 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.
26 function MongooseArray(values, path, doc) { 27 var arr = [].concat(values); 28 29 utils.decorate( arr, MongooseArray.mixin ); 30 arr.isMongooseArray = true; 31 32 var _options = { enumerable: false, configurable: true, writable: true }; 33 var keys = Object.keys(MongooseArray.mixin). 34 concat(['isMongooseArray', 'validators', '_path']); 35 for (var i = 0; i < keys.length; ++i) { 36 Object.defineProperty(arr, keys[i], _options); 37 }; 38 39 arr._atomics = {}; 40 arr.validators = []; 41 arr._path = path; 42 43 // Because doc comes from the context of another function, doc === global 44 // can happen if there was a null somewhere up the chain (see #3020) 45 // RB Jun 17, 2015 updated to check for presence of expected paths instead 46 // to make more proof against unusual node environments 47 if (doc && doc instanceof Document) { 48 arr._parent = doc; 49 arr._schema = doc.schema.path(path); 50 } 51 52 return arr; 53 }
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 }
23 function MongooseDocumentArray (values, path, doc) { 24 var arr = []; 25 arr.push.apply(arr, values); 26 arr.__proto__ = MongooseDocumentArray.prototype; 27 28 arr._atomics = {}; 29 arr.validators = []; 30 arr._path = path; 31 32 if (doc) { 33 arr._parent = doc; 34 arr._schema = doc.schema.path(path); 35 doc.on('save', arr.notify('save')); 36 doc.on('isNew', arr.notify('isNew')); 37 } 38 39 return arr; 40 };
26 function MongooseDocumentArray (values, path, doc) { 27 var arr = []; 28 29 // Values always have to be passed to the constructor to initialize, since 30 // otherwise MongooseArray#push will mark the array as modified to the parent. 31 arr.push.apply(arr, values); 32 arr.__proto__ = MongooseDocumentArray.prototype; 33 34 arr._atomics = {}; 35 arr.validators = []; 36 arr._path = path; 37 38 if (doc) { 39 arr._parent = doc; 40 arr._schema = doc.schema.path(path); 41 doc.on('save', arr.notify('save')); 42 doc.on('isNew', arr.notify('isNew')); 43 } 44 45 return arr; 46 };
24 function MongooseDocumentArray (values, path, doc) { 25 var arr = [].concat(values); 26 27 // Values always have to be passed to the constructor to initialize, since 28 // otherwise MongooseArray#push will mark the array as modified to the parent. 29 utils.decorate( arr, MongooseDocumentArray.mixin ); 30 arr.isMongooseArray = true; 31 arr.isMongooseDocumentArray = true; 32 33 arr._atomics = {}; 34 arr.validators = []; 35 arr._path = path; 36 37 // Because doc comes from the context of another function, doc === global 38 // can happen if there was a null somewhere up the chain (see #3020 && #3034) 39 // RB Jun 17, 2015 updated to check for presence of expected paths instead 40 // to make more proof against unusual node environments 41 if (doc && doc instanceof Document) { 42 arr._parent = doc; 43 arr._schema = doc.schema.path(path); 44 arr._handlers = { 45 isNew: arr.notify('isNew'), 46 save: arr.notify('save') 47 }; 48 49 doc.on('save', arr._handlers.save); 50 doc.on('isNew', arr._handlers.isNew); 51 } 52 53 return arr; 54 }
23 function MongooseDocumentArray(values, path, doc) { 24 var arr = [].concat(values); 25 arr._path = path; 26 27 var props = { 28 isMongooseArray: true, 29 isMongooseDocumentArray: true, 30 validators: [], 31 _atomics: {}, 32 _schema: void 0, 33 _handlers: void 0 34 }; 35 36 // Values always have to be passed to the constructor to initialize, since 37 // otherwise MongooseArray#push will mark the array as modified to the parent. 38 var keysMA = Object.keys(MongooseArray.mixin); 39 var numKeys = keysMA.length; 40 for (var j = 0; j < numKeys; ++j) { 41 arr[keysMA[j]] = MongooseArray.mixin[keysMA[j]]; 42 } 43 44 var keysMDA = Object.keys(MongooseDocumentArray.mixin); 45 numKeys = keysMDA.length; 46 for (var i = 0; i < numKeys; ++i) { 47 arr[keysMDA[i]] = MongooseDocumentArray.mixin[keysMDA[i]]; 48 } 49 50 var keysP = Object.keys(props); 51 numKeys = keysP.length; 52 for (var k = 0; k < numKeys; ++k) { 53 arr[keysP[k]] = props[keysP[k]]; 54 } 55 56 // Because doc comes from the context of another function, doc === global 57 // can happen if there was a null somewhere up the chain (see #3020 && #3034) 58 // RB Jun 17, 2015 updated to check for presence of expected paths instead 59 // to make more proof against unusual node environments 60 if (doc && doc instanceof Document) { 61 arr._parent = doc; 62 arr._schema = doc.schema.path(path); 63 arr._handlers = { 64 isNew: arr.notify('isNew'), 65 save: arr.notify('save') 66 }; 67 68 doc.on('save', arr._handlers.save); 69 doc.on('isNew', arr._handlers.isNew); 70 } 71 72 return arr; 73 }
12 updateSchema( state, key, value ) { 13 14 if( key[0] === '@' ) { 15 16 key = key.substr(1); 17 } 18 19 if( key === 'items' || key === 'ordered' ) { 20 21 if( !Array.isArray( value ) ) { 22 23 // convert to array 24 value = [ value ]; 25 } 26 27 let schemas = []; 28 29 let parseSchemaFunc = this.parseSchema; 30 31 for( let item of value ) { 32 33 let itemSchema = parseSchemaFunc.call( null, item, state.engine ); 34 35 schemas.push( itemSchema ); 36 } 37 38 state.schema = state.schema[ key ].apply( state.schema, schemas ); 39 return true; 40 } 41 42 return super.updateSchema( state, key, value ); 43 }
103 function 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 }
65 async function update ({ id: _id, ...commentInfo }) { 66 const db = await makeDb() 67 const result = await db 68 .collection('comments') 69 .updateOne({ _id }, { $set: { ...commentInfo } }) 70 return result.modifiedCount > 0 ? { id: _id, ...commentInfo } : null 71 }
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 }