MichaelSolati / geofirestore-js

Location-based querying and filtering using Firebase Firestore.
https://geofirestore.com
MIT License
504 stars 58 forks source link

Please how do I use .where() in Geofirestore #111

Closed jerryheir closed 5 years ago

jerryheir commented 5 years ago

Please help. whenever I add .where to my query, docs always return empty when it exists. geocollection: GeoCollectionReference = geofirestore.collection('ewnb') .where("dhhshs", "==", true) .where("hhjhshjs", "==", "iool jhhe"); This simple query return empty when I see it clearly in the db

MichaelSolati commented 5 years ago

Can I see a stackblitz? (Also have you checked the console? It may be an indexing issue.)

jerryheir commented 5 years ago

Okay. const firestore = admin.firestore(), geofirestore: GeoFirestore = new GeoFirestore(firestore), geocollection: GeoCollectionReference = geofirestore.collection('cloud'), query: GeoQuery = geocollection .where("cloudId", "==", "203j28n2mw") .where("status", "==", true) .near({ center: new admin.firestore.GeoPoint(6.4589556, 3.6085704), radius: 10 });

jerryheir commented 5 years ago

Even when I do it without the near method, it still doesnt work const firestore = admin.firestore(), geofirestore: GeoFirestore = new GeoFirestore(firestore), geocollection: GeoCollectionReference = geofirestore.collection('cloud'), query: GeoQuery = geocollection .where("cloudId", "==", "203j28n2mw") .where("status", "==", true);

const value = await query.get();

jerryheir commented 5 years ago

It always only returns [], empty array

MichaelSolati commented 5 years ago

So this should/would normally work, and if it's not working for you I'll need to see more of the environment you're working in. If you can provide a sample app or a stackblitz that would be helpful and necessary.

jerryheir commented 5 years ago

https://stackblitz.com/edit/typescript-rtnjz3

It's a firebase cloud function. It is run in a try catch, nothing breaks. Its just that it returns [], The url about is the stackblitz editor so you can have an idea of what is basically there. Thanks for your response, I really appreciate

MichaelSolati commented 5 years ago

Again code looks good, but I can't execute/run this code, it don't have a firebase project. Can you make this a basic web app or something I can execute to test or see what's happening? Here, you can modify this, https://stackblitz.com/edit/typescript-qg74c8?file=index.ts I just need your app variables so it'll initialize.

jerryheir commented 5 years ago

Jeez, I updated it with real values And it worked. How come

jerryheir commented 5 years ago

import * as firebase from 'firebase/app'; import 'firebase/firestore'; Only difference is that you use the above, how can I get that working on a firebase cloud function. It doesnt let me

jerryheir commented 5 years ago

TypeError: firebase.firestore is not a function

Unhandled error Error: Unknown error status: TypeError: firebase.firestore is not a function

MichaelSolati commented 5 years ago

You're doing this in a cloud function you said? What version of admin/function are you using?

jerryheir commented 5 years ago

My friend @MichaelSolati It worked now.So the imports was the problem, Its been a while I did Typescript and this cloud functions is in typescript i was doing this

import * as firebase from 'firebase/app'; import 'firebase/firestore';

Just as I saw in the examples, when I should have been doing

import { firebase } from '@firebase/app'; import '@firebase/firestore'; I thank you for all you have done. Without replicating the issue I wouldn't have seen the bug. Thanks a lot

jerryheir commented 5 years ago

The firebase admin also works. Just tested it.