Merge pull request #28481 from overleaf/oa-access-secondary-mongo

[web] Prefer secondary Mongo for get emails script

GitOrigin-RevId: 84cf1d23b056a4d4a738f1783059d2309997d912
This commit is contained in:
Olzhas Askar
2025-09-15 08:05:51 +00:00
committed by Copybot
parent 1f68e3d374
commit 2f5c3c913c
+16 -8
View File
@@ -2,7 +2,11 @@ import { scriptRunner } from './lib/ScriptRunner.mjs'
import fs from 'node:fs'
import readline from 'node:readline'
import minimist from 'minimist'
import { db, ObjectId } from '../app/src/infrastructure/mongodb.js'
import {
db,
ObjectId,
READ_PREFERENCE_SECONDARY,
} from '../app/src/infrastructure/mongodb.js'
/**
* This script extracts user emails given a list of newline separated IDs
@@ -64,14 +68,18 @@ function parseArgs() {
async function processBatch(idBatch, writeStream) {
try {
const cursor = db.users
.find({
const cursor = db.users.find(
{
_id: { $in: idBatch },
})
.project({
_id: 0,
email: 1,
})
},
{
projection: {
_id: 0,
email: 1,
},
readPreference: READ_PREFERENCE_SECONDARY,
}
)
for await (const doc of cursor) {
if (doc.email) {