|
1 | 1 | 'use strict';
|
2 | 2 | const Parse = require('parse/node');
|
3 | 3 | const request = require('../lib/request');
|
| 4 | +const Config = require('../lib/Config'); |
4 | 5 |
|
5 | 6 | const masterKeyHeaders = {
|
6 | 7 | 'X-Parse-Application-Id': 'test',
|
@@ -1429,31 +1430,41 @@ describe('Parse.Query Aggregate testing', () => {
|
1429 | 1430 | }
|
1430 | 1431 | );
|
1431 | 1432 |
|
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 | + ); |
1433 | 1445 | // 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]); |
1438 | 1450 | // Create query
|
1439 | 1451 | const pipeline = [
|
1440 | 1452 | {
|
1441 | 1453 | geoNear: {
|
1442 | 1454 | near: {
|
1443 | 1455 | type: 'Point',
|
1444 |
| - coordinates: [10.5, -10.5], |
| 1456 | + coordinates: [1, 1] |
1445 | 1457 | },
|
1446 | 1458 | key: 'location',
|
1447 | 1459 | spherical: true,
|
1448 | 1460 | distanceField: 'dist',
|
1449 |
| - includeLocs: 'loc', |
1450 | 1461 | query: {
|
1451 | 1462 | date: {
|
1452 |
| - $gte: new Date(1), |
1453 |
| - }, |
1454 |
| - }, |
1455 |
| - }, |
1456 |
| - }, |
| 1463 | + $gte: new Date(2000) |
| 1464 | + } |
| 1465 | + } |
| 1466 | + } |
| 1467 | + } |
1457 | 1468 | ];
|
1458 | 1469 | const query = new Parse.Query(TestObject);
|
1459 | 1470 | const results = await query.aggregate(pipeline);
|
|
0 commit comments