10 examples of 'mongodb find in array' in JavaScript

Every line of 'mongodb find in array' 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
12function find(array, callback) {
13 for (var i = 0; i < array.length; i++) {
14 if (callback(array[i], i, array)) {
15 return array[i];
16 }
17 }
18}
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

113function find(arr, callback) {
114 return arr[findIndex(arr, callback)];
115}
13function find (array, id) {
14 if(!id) return
15 for (var k in array) {
16 if(array[k].id == id) return array[k]
17 }
18}
51async dbFind(db, id) {
52 return await conn.collection(db).findOne(
53 id
54 );
55}
152findManyById(ids) {
153 return this.loader.loadMany(ids);
154}
49async findManyById(ids: string[]): Promise<DOC[]> {
50 const collection = await this.collection;
51 const found = await collection.find({ _id: { $in: ids.map(id => new ObjectID(id)) } }).toArray();
52
53 const results: DOC[] = [];
54 for (const result of found) {
55 results.push(await this.invokeEvents(POST_KEY, ['find', 'findMany'], this.toggleId(result, false)));
56 }
57
58 return results;
59}
7export function findObject (array, property, value) {
8 for (let i = 0; i < array.length; i++) {
9 if (array[i][property] === value) {
10 return array[i]
11 }
12 }
13
14 return null
15}
10export function findIndex<A>(array: A[], callback: (item: A) => boolean) {
11 const found = array.find(callback);
12 if (found) {
13 return array.indexOf(found);
14 }
15 return -1;
16}
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}
56public async find(where: IWhere, language: string) {
57 const results = await this.i18nModel.find({
58 id: { $in: where.ids },
59 type: where.type,
60 language,
61 }).exec();
62
63 return results.reduce((obj, item) => {
64 obj[item.id] = item.data;
65 return obj;
66 }, {});
67}

Related snippets