Skip to content

Commit 96a9588

Browse files
NotBobTheBuilderTylerBrock
authored andcommitted
MongoDB $or Queries avoid SERVER-13732 bug (#3476)
MongoDB has an unfixed bug in all supported versions 2.6-3.4 which results in suboptimal index usage for `$or` queries when the query has implicit `$and`s at the query root. When adding `_rperm` to `$or` queries, Parse accidentally creates queries which hit this bug. The fix in this commit applies the suggested workaround of putting the `_rperm` property inside all `$or` subdocuments, moving it from the top level and leaving `$or` as the only top-level operator. MongoDB Bug Link: https://jira.mongodb.org/browse/SERVER-13732
1 parent 66cdfae commit 96a9588

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Controllers/DatabaseController.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ function addWriteACL(query, acl) {
1818
function addReadACL(query, acl) {
1919
const newQuery = _.cloneDeep(query);
2020
//Can't be any existing '_rperm' query, we don't allow client queries on that, no need to $and
21-
newQuery._rperm = { "$in" : [null, "*", ...acl]};
21+
if (newQuery.hasOwnProperty('$or')) {
22+
newQuery.$or = newQuery.$or.map(function(qobj) {
23+
qobj._rperm = {'$in' : [null, '*', ...acl]};
24+
return qobj;
25+
});
26+
} else {
27+
newQuery._rperm = { "$in" : [null, "*", ...acl]};
28+
}
2229
return newQuery;
2330
}
2431

0 commit comments

Comments
 (0)