10 examples of 'mongoose findall' in JavaScript

Every line of 'mongoose findall' 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
40findAll(cb) {
41 this.collection.find({}, (err, res) => {
42 if (err) return cb(err);
43 const obj = JSON.parse(JSON.stringify(res));
44 return cb(null, obj);
45 });
46}
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

86this.findAll = function findAll(collection, cb) {
87 cb = cb || nop;
88 var col = collections[collection];
89 if (!col) {
90 cb('Attempt to read from unknown collection "' + collection + '"');
91 return;
92 }
93 col.find({}).toArray(function(err, items) {
94 if (err) {
95 cb(err);
96 return;
97 }
98 cb(null, items);
99 });
100};
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}
90function find(options, callback) {
91 mongoose.connection.db.collection(options.collection, function(err, collection) {
92 collection.find(options.query).skip(options.offset).limit(options.limit).toArray(callback);
93 });
94}
165function findAll(model, options, tx, callback) {
166 var
167 parsed = parseFindOptions(model, options, false),
168 select = parsed.select,
169 where = parsed.where,
170 append = parsed.append,
171 params = parsed.params,
172 sql = where ?
173 utils.format('select %s from `%s` where %s %s', select, model.__table, where, append) :
174 utils.format('select %s from `%s` %s', select, model.__table, append);
175 smartRunSQL(model.__pool, sql, params, tx, function (err, results) {
176 if (err) {
177 return callback(err);
178 }
179 return callback(null, _.map(results, function (r) {
180 return model.__warp.__createInstance(model, r);
181 }));
182 });
183}
22async function findAll(savedObjectsClient, findOptions, page = 1, allObjects = []) {
23 const objects = await savedObjectsClient.find({
24 ...findOptions,
25 page
26 });
27
28 allObjects.push(...objects.saved_objects);
29 if (allObjects.length < objects.total) {
30 return findAll(savedObjectsClient, findOptions, page + 1, allObjects);
31 }
32
33 return allObjects;
34}
51async dbFind(db, id) {
52 return await conn.collection(db).findOne(
53 id
54 );
55}
417async find(options){
418 options = await this.parseOptions(options, {limit: 1}, true);
419 options = await this.beforeFind(options);
420 let data = await this.db().select(options);
421 return this.afterFind(data[0] || {}, options);
422}
40db.projects.findOne({_id : db.ObjectId(id)}, function onFound(err, docs) {
41 if (err) {
42 throw err;
43 }
44
45 if (!docs) {
46 callback(null);
47 return;
48 }
49 callback(docs.assetFolder);
50});
88async find(req: FindRequest = { conditions: {} }): Promise<DOC[]> {
89 const collection = await this.collection;
90
91 const conditions = this.toggleId(req.conditions, true);
92 let cursor = collection.find(conditions);
93
94 if (req.projection) {
95 cursor = cursor.project(req.projection);
96 }
97
98 if (req.sort) {
99 cursor = cursor.sort(req.sort);
100 }
101
102 if (req.skip) {
103 cursor = cursor.skip(req.skip);
104 }
105
106 if (req.limit) {
107 cursor = cursor.limit(req.limit);
108 }
109
110 const newDocuments = await cursor.toArray();
111 const results = [];
112
113 for (let document of newDocuments) {
114 document = this.toggleId(document, false);
115 document = await this.invokeEvents(POST_KEY, ['find', 'findMany'], document);
116 results.push(document);
117 }
118
119 return results;
120}

Related snippets