Skip to content

Commit 8ab3c95

Browse files
committed
chore: try without setting "allUsers"
1 parent 10b2237 commit 8ab3c95

File tree

1 file changed

+48
-28
lines changed

1 file changed

+48
-28
lines changed

packages/data-service/src/data-service.ts

Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2140,37 +2140,57 @@ class DataServiceImpl extends WithLogContext implements DataService {
21402140
progress: number;
21412141
};
21422142

2143-
const currentOps: IndexProgressResult[] = await this._database(
2144-
'admin',
2145-
'META'
2146-
)
2147-
.aggregate([
2148-
{ $currentOp: { allUsers: true, localOps: true } }, // get all ops
2149-
{
2150-
$match: {
2151-
ns,
2152-
progress: { $type: 'object' },
2153-
'command.createIndexes': { $exists: true },
2154-
},
2155-
}, // filter for createIndexes
2156-
{ $unwind: '$command.indexes' }, // explode the "indexes" array for each createIndexes command
2157-
{
2158-
$group: {
2159-
_id: '$command.indexes.name',
2160-
progress: {
2161-
$first: {
2162-
$cond: {
2163-
if: { $gt: ['$progress.total', 0] },
2164-
then: { $divide: ['$progress.done', '$progress.total'] },
2165-
else: 0,
2166-
},
2143+
const currentOp = { $currentOp: { allUsers: true, localOps: false } };
2144+
const pipeline = [
2145+
// get all ops
2146+
currentOp,
2147+
{
2148+
// filter for createIndexes commands
2149+
$match: {
2150+
ns,
2151+
progress: { $type: 'object' },
2152+
'command.createIndexes': { $exists: true },
2153+
},
2154+
},
2155+
{
2156+
// explode the "indexes" array for each createIndexes command
2157+
$unwind: '$command.indexes',
2158+
},
2159+
{
2160+
// group on index name
2161+
$group: {
2162+
_id: '$command.indexes.name',
2163+
progress: {
2164+
$first: {
2165+
$cond: {
2166+
if: { $gt: ['$progress.total', 0] },
2167+
then: { $divide: ['$progress.done', '$progress.total'] },
2168+
else: 0,
21672169
},
21682170
},
21692171
},
2170-
}, // group on index name
2171-
])
2172-
.toArray()
2173-
.then(undefined, () => []);
2172+
},
2173+
},
2174+
];
2175+
2176+
let currentOps: IndexProgressResult[] = [];
2177+
const db = this._database('admin', 'META');
2178+
2179+
try {
2180+
currentOps = (await db
2181+
.aggregate(pipeline)
2182+
.toArray()) as IndexProgressResult[];
2183+
} catch {
2184+
// Try limiting the permissions needed:
2185+
currentOp.$currentOp.allUsers = false;
2186+
try {
2187+
currentOps = (await db
2188+
.aggregate(pipeline)
2189+
.toArray()) as IndexProgressResult[];
2190+
} catch {
2191+
// ignore errors
2192+
}
2193+
}
21742194

21752195
const indexToProgress = Object.create(null);
21762196
for (const { _id, progress } of currentOps) {

0 commit comments

Comments
 (0)