10 examples of 'mongodb nodejs findone' in JavaScript

Every line of 'mongodb nodejs findone' 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
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}
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

51async dbFind(db, id) {
52 return await conn.collection(db).findOne(
53 id
54 );
55}
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}
150findOne(collection) {
151 return new MongoDBOperation('findOne', collection, this, (collection, args, cb) => {
152 collection.findOne(args.query || {}, args.projection || {}, (err, item) => {
153 if (err) return cb(err);
154 if (!item) return cb(new Error("Not found"));
155 cb(null, item);
156 });
157 });
158}
127findOne(...args) {
128 return this.get().findOne(...args);
129}
54findOne(id, cb) {
55 const self = this;
56 self.collection.findOne({
57 _id: id
58 }).lean().exec((err, res) => {
59 if (err) { return cb(err); }
60 cb(null, JSON.parse(JSON.stringify(res)));
61 });
62}
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}
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}
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<RoomListingData>;
65}
80findOne(id, cb) {
81 const self = this;
82 return pg(done => self.collection.findOne({
83 _id: id
84 }).lean().exec((err, res) => {
85 if (err) {
86 return done(err);
87 }
88 parse(res);
89 done(null, res);
90 }), cb);
91}

Related snippets