Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

await get(query) not working in Firebase Functions #98

Open
Deathblade6 opened this issue Feb 13, 2020 · 1 comment
Open

await get(query) not working in Firebase Functions #98

Deathblade6 opened this issue Feb 13, 2020 · 1 comment

Comments

@Deathblade6
Copy link

Deathblade6 commented Feb 13, 2020

I am using geofirex in Firebase Cloud Functions using the following code:

const functions = require('firebase-functions');
 const firebase = require('firebase-admin');
firebase.initializeApp(functions.config.firebase);
const geo = require('geofirex').init(firebase);
var { get } = require('geofirex')
const firestore = firebase.firestore();
const settings = {
  timestampsInSnapshots: true
}
firestore.settings(settings)
const hostels = firestore.collection('hostels');
exports.helloWorld = functions.https.onRequest((request, response) => {
  const position = geo.point(40, -119);
  hostels.add({ name: 'Phoenix', position });
  response.send("Hello from Firebase!");
});
exports.search = functions.https.onRequest((request,response) => {
  // const center = geo.point(request.body.location[0],request.body.location[1]);
  const center = geo.point(40,-119);
  const radius = 1;
  const field  = 'position';
  getRooms(center,radius,field).then((res) => {
      console.log(res);
  }).catch((err) => {
      console.log("err"+err);
  });
  response.send("Atleast this much");
})
async function getRooms(center,radius,field) {
    const query = geo.query(hostels).within(center,radius,field);
    const snap = await get(query);
    console.log(query);
}

When executing, the code to save the data into firestore works perfectly and creates the hash and all, but the value of query when searching is returned as

Observable {
  _isScalar: false,
  source: 
   Observable {
     _isScalar: false,
     source: Observable { _isScalar: false, source: [Object], operator: [Object] },
     operator: [Function: shareReplayOperation] },
  operator: FinallyOperator { callback: [Function] } }

res has value undefined.

Does anyone know how to fix this?

@Deathblade6 Deathblade6 changed the title await get(query) not working in FIrebase Functions await get(query) not working in Firebase Functions Feb 13, 2020
@sserdyuk
Copy link

sserdyuk commented Apr 5, 2020

Geofirex internally ises RxJs observables. geo.query returns an observable, get converts it to a promise, your snap is actually an array of matched hotels ordered by distance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants