5 examples of 'findone mongodb nodejs' in JavaScript

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.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
51async dbFind(db, id) {
52 return await conn.collection(db).findOne(
53 id
54 );
55}
Important

Use secure code every time

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

127async findOne(collectionName: string, query, fields = {}, options = {}): Promise<IResult> {
128 const collection = await this.getCollenction(collectionName);
129 options = Object.assign({}, options, { projection: fields });
130 return await collection.findOne(query, options);
131}
82findOne(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}
61public async findOneById(id: string): Promise<any> {
62 const filteredData = await this.db.collection(this.collectionName)
63 .find({ id })
64 .project({ _id: 0 })
65 .toArray();
66 return first(filteredData);
67}
88function findOne<T>(db: Nedb, query: object): Promise<Maybe<T>> {
89 return new Promise((resolve, reject) => {
90 db.findOne<T>(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}

Related snippets