Avoid multiple $nears in one query (#3798)
Mongo has a hard limit on 1 $near operation per query. Restructuring to avoid SERVER-13732 should not invalidate a query by creating multiple $near operations. Additionally, queries with multiple $ors are now recursively handled, whereas before, ops at the top level would only have been pushed one level deeper. https://github.com/parse-community/parse-server/issues/3767
This commit is contained in:
committed by
Florent Vilmart
parent
64e6f40779
commit
7b9ebc4e8e
@@ -13,6 +13,29 @@ describe('DatabaseController', function() {
|
||||
done();
|
||||
});
|
||||
|
||||
it('should not restructure SERVER-13732 queries with $nears', (done) => {
|
||||
var query = {$or: [{a: 1}, {b: 1}], c: {$nearSphere: {}}};
|
||||
validateQuery(query);
|
||||
expect(query).toEqual({$or: [{a: 1}, {b: 1}], c: {$nearSphere: {}}});
|
||||
|
||||
query = {$or: [{a: 1}, {b: 1}], c: {$near: {}}};
|
||||
validateQuery(query);
|
||||
expect(query).toEqual({$or: [{a: 1}, {b: 1}], c: {$near: {}}});
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
|
||||
it('should push refactored keys down a tree for SERVER-13732', (done) => {
|
||||
var query = {a: 1, $or: [{$or: [{b: 1}, {b: 2}]},
|
||||
{$or: [{c: 1}, {c: 2}]}]};
|
||||
validateQuery(query);
|
||||
expect(query).toEqual({$or: [{$or: [{b: 1, a: 1}, {b: 2, a: 1}]},
|
||||
{$or: [{c: 1, a: 1}, {c: 2, a: 1}]}]});
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it('should reject invalid queries', (done) => {
|
||||
expect(() => validateQuery({$or: {'a': 1}})).toThrow();
|
||||
done();
|
||||
|
||||
Reference in New Issue
Block a user