Skip to content

Commit 124826a

Browse files
committed
added geo index creation to test case
1 parent 979b25e commit 124826a

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

spec/ParseQuery.Aggregate.spec.js

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22
const Parse = require('parse/node');
33
const request = require('../lib/request');
4+
const Config = require('../lib/Config');
45

56
const masterKeyHeaders = {
67
'X-Parse-Application-Id': 'test',
@@ -1429,31 +1430,41 @@ describe('Parse.Query Aggregate testing', () => {
14291430
}
14301431
);
14311432

1432-
it('geoNear with location query', async () => {
1433+
it_only_db('mongo')('geoNear with location query', async () => {
1434+
// Create geo index which is required for `geoNear` query
1435+
const database = Config.get(Parse.applicationId).database;
1436+
const schema = await new Parse.Schema('TestObject').get();
1437+
await database.adapter.ensureIndex(
1438+
'TestObject',
1439+
schema,
1440+
['location'],
1441+
'geoIndex',
1442+
false,
1443+
"2dsphere"
1444+
);
14331445
// Create objects
1434-
const obj1 = new TestObject({ value: 1, location: new Parse.GeoPoint(10.5, -10.5), date: new Date(0) });
1435-
const obj2 = new TestObject({ value: 2, location: new Parse.GeoPoint(11.5, -10.5), date: new Date(1) });
1436-
const obj3 = new TestObject({ value: 3, location: new Parse.GeoPoint(12.5, -10.5), date: new Date(2) });
1437-
await Parse.Object.saveAll(obj1, obj2, obj3);
1446+
const obj1 = new TestObject({ value: 1, location: new Parse.GeoPoint(1, 1), date: new Date(1000) });
1447+
const obj2 = new TestObject({ value: 2, location: new Parse.GeoPoint(1, 1), date: new Date(2000) });
1448+
const obj3 = new TestObject({ value: 3, location: new Parse.GeoPoint(1, 1), date: new Date(3000) });
1449+
await Parse.Object.saveAll([obj1, obj2, obj3]);
14381450
// Create query
14391451
const pipeline = [
14401452
{
14411453
geoNear: {
14421454
near: {
14431455
type: 'Point',
1444-
coordinates: [10.5, -10.5],
1456+
coordinates: [1, 1]
14451457
},
14461458
key: 'location',
14471459
spherical: true,
14481460
distanceField: 'dist',
1449-
includeLocs: 'loc',
14501461
query: {
14511462
date: {
1452-
$gte: new Date(1),
1453-
},
1454-
},
1455-
},
1456-
},
1463+
$gte: new Date(2000)
1464+
}
1465+
}
1466+
}
1467+
}
14571468
];
14581469
const query = new Parse.Query(TestObject);
14591470
const results = await query.aggregate(pipeline);

0 commit comments

Comments
 (0)