@@ -1430,15 +1430,15 @@ describe('Parse.Query Aggregate testing', () => {
1430
1430
}
1431
1431
) ;
1432
1432
1433
- it_only_db ( 'mongo' ) ( 'geoNear with location query' , async ( ) => {
1433
+ it_only_db ( 'mongo' ) ( 'aggregate geoNear with location query' , async ( ) => {
1434
1434
// Create geo index which is required for `geoNear` query
1435
1435
const database = Config . get ( Parse . applicationId ) . database ;
1436
1436
const schema = await new Parse . Schema ( 'GeoObject' ) . save ( ) ;
1437
1437
await database . adapter . ensureIndex (
1438
1438
'GeoObject' ,
1439
1439
schema ,
1440
1440
[ 'location' ] ,
1441
- 'geoIndex' ,
1441
+ undefined ,
1442
1442
false ,
1443
1443
{ indexType : '2dsphere' } ,
1444
1444
) ;
@@ -1474,4 +1474,77 @@ describe('Parse.Query Aggregate testing', () => {
1474
1474
expect ( results [ 0 ] . value ) . toEqual ( 2 ) ;
1475
1475
expect ( results [ 1 ] . value ) . toEqual ( 3 ) ;
1476
1476
} ) ;
1477
+
1478
+ it_only_db ( 'mongo' ) ( 'aggregate geoNear with near GeoJSON point' , async ( ) => {
1479
+ // Create geo index which is required for `geoNear` query
1480
+ const database = Config . get ( Parse . applicationId ) . database ;
1481
+ const schema = await new Parse . Schema ( 'GeoObject' ) . save ( ) ;
1482
+ await database . adapter . ensureIndex (
1483
+ 'GeoObject' ,
1484
+ schema ,
1485
+ [ 'location' ] ,
1486
+ undefined ,
1487
+ false ,
1488
+ '2dsphere'
1489
+ ) ;
1490
+ // Create objects
1491
+ const GeoObject = Parse . Object . extend ( 'GeoObject' ) ;
1492
+ const obj1 = new GeoObject ( { value : 1 , location : new Parse . GeoPoint ( 1 , 1 ) , date : new Date ( 1 ) } ) ;
1493
+ const obj2 = new GeoObject ( { value : 2 , location : new Parse . GeoPoint ( 2 , 1 ) , date : new Date ( 2 ) } ) ;
1494
+ const obj3 = new GeoObject ( { value : 3 , location : new Parse . GeoPoint ( 3 , 1 ) , date : new Date ( 3 ) } ) ;
1495
+ await Parse . Object . saveAll ( [ obj1 , obj2 , obj3 ] ) ;
1496
+ // Create query
1497
+ const pipeline = [
1498
+ {
1499
+ geoNear : {
1500
+ near : {
1501
+ type : 'Point' ,
1502
+ coordinates : [ 1 , 1 ]
1503
+ } ,
1504
+ key : 'location' ,
1505
+ spherical : true ,
1506
+ distanceField : 'dist'
1507
+ }
1508
+ }
1509
+ ] ;
1510
+ const query = new Parse . Query ( GeoObject ) ;
1511
+ const results = await query . aggregate ( pipeline ) ;
1512
+ // Check results
1513
+ expect ( results . length ) . toEqual ( 3 ) ;
1514
+ } ) ;
1515
+
1516
+ it_only_db ( 'mongo' ) ( 'aggregate geoNear with near legacy coordinate pair' , async ( ) => {
1517
+ // Create geo index which is required for `geoNear` query
1518
+ const database = Config . get ( Parse . applicationId ) . database ;
1519
+ const schema = await new Parse . Schema ( 'GeoObject' ) . save ( ) ;
1520
+ await database . adapter . ensureIndex (
1521
+ 'GeoObject' ,
1522
+ schema ,
1523
+ [ 'location' ] ,
1524
+ undefined ,
1525
+ false ,
1526
+ '2dsphere'
1527
+ ) ;
1528
+ // Create objects
1529
+ const GeoObject = Parse . Object . extend ( 'GeoObject' ) ;
1530
+ const obj1 = new GeoObject ( { value : 1 , location : new Parse . GeoPoint ( 1 , 1 ) , date : new Date ( 1 ) } ) ;
1531
+ const obj2 = new GeoObject ( { value : 2 , location : new Parse . GeoPoint ( 2 , 1 ) , date : new Date ( 2 ) } ) ;
1532
+ const obj3 = new GeoObject ( { value : 3 , location : new Parse . GeoPoint ( 3 , 1 ) , date : new Date ( 3 ) } ) ;
1533
+ await Parse . Object . saveAll ( [ obj1 , obj2 , obj3 ] ) ;
1534
+ // Create query
1535
+ const pipeline = [
1536
+ {
1537
+ geoNear : {
1538
+ near : [ 1 , 1 ] ,
1539
+ key : 'location' ,
1540
+ spherical : true ,
1541
+ distanceField : 'dist'
1542
+ }
1543
+ }
1544
+ ] ;
1545
+ const query = new Parse . Query ( GeoObject ) ;
1546
+ const results = await query . aggregate ( pipeline ) ;
1547
+ // Check results
1548
+ expect ( results . length ) . toEqual ( 3 ) ;
1549
+ } ) ;
1477
1550
} ) ;
0 commit comments