From 598eaf08fdd2e01fb1214b7b7a72b0f4fb433896 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Thu, 16 May 2024 14:34:58 +0100 Subject: [PATCH] Merge pull request #17816 from overleaf/bg-eslint-rule-for-find-with-await add eslint rule for find with await GitOrigin-RevId: 7e78104e610073ff3c151d7314753c8301a8c787 --- services/web/.eslintrc | 5 +++++ services/web/scripts/split_tests_assigned_at_to_dates.js | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/services/web/.eslintrc b/services/web/.eslintrc index 1dcae0df5f..fbeea4bd3d 100644 --- a/services/web/.eslintrc +++ b/services/web/.eslintrc @@ -133,6 +133,11 @@ { "selector": "CallExpression[callee.property.name='map'] Identifier[name='ObjectId']:first-child, CallExpression[callee.property.name='map'] MemberExpression[property.name='ObjectId']:first-child", "message": "Don't map ObjectId directly. Use `id => new ObjectId(id)` instead" + }, + // Catch incorrect usage of `await db.collection.find()` + { + "selector": "AwaitExpression > CallExpression > MemberExpression[property.name='find'][object.object.name='db']", + "message": "Mongo find returns a cursor not a promise, use `for await (const result of cursor)` or `.toArray()` instead." } ] } diff --git a/services/web/scripts/split_tests_assigned_at_to_dates.js b/services/web/scripts/split_tests_assigned_at_to_dates.js index 9df234cbb6..171314f502 100644 --- a/services/web/scripts/split_tests_assigned_at_to_dates.js +++ b/services/web/scripts/split_tests_assigned_at_to_dates.js @@ -2,7 +2,7 @@ const { db, waitForDb } = require('../app/src/infrastructure/mongodb') async function updateStringDates() { await waitForDb() - const users = await db.users.find({ + const users = db.users.find({ splitTests: { $exists: true }, })