Every line of 'mongoose insertone' 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.
34 insertOne(doc) { 35 return this.constructor._getCollection(this.collection) 36 .then(function(db) { 37 return new Promise((resolve, reject) => { 38 db.insert(doc, function (err, newDoc) { 39 if(err) { 40 reject(err); 41 } 42 else { 43 resolve(newDoc); 44 } 45 }); 46 }); 47 }); 48 }
Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code
40 insertOne(doc) { 41 if (!doc) return Promise.reject(new errors.InvalidArugmentError('doc is required')); 42 43 let cursor = this._dbCollection.insertOne(doc); 44 45 return new MongotronCursor(cursor); 46 }
78 Insert(collection, data) { 79 var self = this; 80 81 return new Promise(function (resolve, reject) { 82 var _collection = self.DB.collection(collection); 83 _collection.insert(data, function (err, result) { 84 if(err){ 85 reject(err); 86 return; 87 } 88 resolve(result); 89 }); 90 }); 91 }
278 insertMany(docs: ObjectLiteral[], options?: CollectionInsertManyOptions): Promise<InsertWriteOpResult> { 279 return this.manager.insertMany(this.metadata.tableName, docs, options); 280 }
89 insert(options: IOptions): Promise<IMongoResult> { 90 let self:Mongo = this; 91 return new Promise((resolve, reject) => { 92 try { 93 self.db.collection(options.tbName).insert(options.data, options || {}, (err, docs) => { 94 err ? reject({ 95 ok: -1, 96 es: err 97 }) : resolve({ 98 ok: 1, 99 es: docs.result, 100 obj: docs 101 }); 102 }); 103 } catch (e) { 104 reject({ 105 ok: -1, 106 es: e 107 }); 108 } 109 }); 110 }
139 function toInsertOneOperation<T extends Entity>(entity: EntityWithPartialId<T>): object { 140 const document = toMongoDocumentWithPartialId(entity); 141 142 const operation = { 143 insertOne: { 144 document 145 } 146 }; 147 148 return operation; 149 }
62 insert(doc) { 63 const cmd = this.ensureCommand('insert', 'documents'); 64 65 doc._id = doc._id || oid(); 66 cmd.documents.push(doc); 67 }
46 insert(table, sets, callback) { 47 try { 48 checkParams({table, sets, callback}) 49 } catch (err) { 50 return callback(err) 51 } 52 if (this._readonly) { 53 return errNotAllowd(callback) 54 } 55 this._conn.collection(table).insert( 56 _.cloneDeep(sets), 57 {castIds: false}, 58 (err, result) => { 59 if (err) { 60 return callback(err) 61 } 62 if (result.constructor === Object) { 63 result = [result] 64 } 65 return callback(err, { 66 affected_rows: result.length, 67 docs: result, 68 }, null) 69 }) 70 }
45 function insert (callback) { 46 if (typeof instance.name !== 'string' || instance.name.length === 0) { 47 return callback(new Error("Invalid name for the " + type)); 48 } 49 50 if (typeof instance.position === 'undefined'){ 51 if(type === 'list') { 52 wunderlist.database.getLastListPosition(function(err, position){ 53 instance.position = position; 54 insertPhase2(callback); 55 }); 56 } else if(type === 'task') { 57 wunderlist.database.getLastTaskPosition(instance.list_id, function(err, position){ 58 instance.position = position; 59 insertPhase2(callback); 60 }); 61 } 62 } else { 63 insertPhase2(callback); 64 } 65 }
97 function insertList(key, value) { 98 return module.exports.listsCollection.updateOne({ _id: key }, { $set: { value } }, { upsert: true }); 99 }