diff --git a/src/GeoQuery.ts b/src/GeoQuery.ts index d0d0469..bab9ba7 100644 --- a/src/GeoQuery.ts +++ b/src/GeoQuery.ts @@ -92,7 +92,7 @@ export class GeoQuery { * Creates and returns a new GeoQuery that's additionally limited to only return up to the specified number of documents. * * This function returns a new (immutable) instance of the GeoQuery (rather than modify the existing instance) to impose the limit. - * + * * Note: Limits on geoqueries are applied based on the distance from the center. Geoqueries require an aggregation of queries. * When performing a geoquery the library applies the limit on the client. This may mean you are loading to the client more documents * then you intended. Use with this performance limitation in mind. @@ -139,6 +139,7 @@ export class GeoQuery { opStr: GeoFirestoreTypes.WhereFilterOp, value: any ): GeoQuery { + // Return GeoQuery return new GeoQuery(this._query.where((fieldPath ? ('d.' + fieldPath) : fieldPath), opStr, value), this._queryCriteria); } @@ -157,7 +158,7 @@ export class GeoQuery { // decode the geohash query string const query: string[] = this._stringToQuery(toQueryStr); // Create the Firebase query - return this._query.where('g', '>=', query[0]).where('g', '<=', query[1]) as GeoFirestoreTypes.web.Query; + return this._query.orderBy('g').startAt(query[0]).endAt(query[1]) as GeoFirestoreTypes.web.Query; }); } diff --git a/test/GeoQuery.test.ts b/test/GeoQuery.test.ts index 16f04cb..d3ba474 100644 --- a/test/GeoQuery.test.ts +++ b/test/GeoQuery.test.ts @@ -443,6 +443,21 @@ describe('GeoQuery Tests:', () => { }); }); + describe('near().where():', () => { + it('near().where() does not throw an error with valid arguments', () => { + const query = new GeoQuery(collection); + expect(() => query.near({ center: new firebase.firestore.GeoPoint(0, 0), radius: 100 }) + .where('count', '==', 0)).not.to.throw(); + expect(() => query.near({ center: new firebase.firestore.GeoPoint(1, 1) }) + .where('count', '>', 0)).not.to.throw(); + expect(() => query.near({ radius: 500 }) + .where('count', '<=', 0)).not.to.throw(); + expect(() => query.near({ radius: 500 }) + .where('array', 'array-contains', 'one')).not.to.throw(); + }); + }); + + describe('_stringToQuery():', () => { it('_stringToQuery() returns an array of two string elements', () => { const query = new GeoQuery(collection);