Every line of 'findone mongodb nodejs' 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.
51 async dbFind(db, id) { 52 return await conn.collection(db).findOne( 53 id 54 ); 55 }
127 async findOne(collectionName: string, query, fields = {}, options = {}): Promise { 128 const collection = await this.getCollenction(collectionName); 129 options = Object.assign({}, options, { projection: fields }); 130 return await collection.findOne(query, options); 131 }
82 findOne(collection, query) { 83 var that = this; 84 query = castQueryIds(query); 85 return new Promise(function(resolve, reject) { 86 var db = that._mongo.collection(collection); 87 db.findOne(query, function (error, doc) { 88 if (error) return reject(error); 89 return resolve(doc); 90 }); 91 }); 92 }
61 public async findOneById(id: string): Promise { 62 const filteredData = await this.db.collection(this.collectionName) 63 .find({ id }) 64 .project({ _id: 0 }) 65 .toArray(); 66 return first(filteredData); 67 }
88 function findOne(db: Nedb, query: object): Promise> { 89 return new Promise((resolve, reject) => { 90 db.findOne(query, (error, doc) => { 91 if (error) { 92 return reject( 93 `An error happened whiling handling findOne: ${query} - ${error}` 94 ); 95 } 96 if (doc) { 97 resolve(doc as T); 98 } else { 99 resolve(null); 100 } 101 }); 102 }); 103 }