3

Is there anyway i can escape GeoPoint as first order in this postion? If i remove GeoPoint from orderby it triggered the below error and if i put the GeoPoint as first orderby, as instructed as below, it mislead the second orderby priceSort..

Uncaught Error: Invalid query. You have a where filter with an inequality (<, <=, >, or >=) on field 'GeoPoint' and so you must also use 'GeoPoint' as your first Query.orderBy(), but your first Query.orderBy() is on field 'priceSort' instead.

 const locations=NearBy({
      center:{
        latitude:4*.*****,
        longitude:7*.*****},
      radius:30000})



    var db = firebase.firestore();
    var AdsQry = db.collection("ads");

      AdsQry = AdsQry
        .where('GeoPoint', '>', locations.lesserGeopoint)
        .where('GeoPoint', '<', locations.greaterThan)
        .orderBy('GeoPoint', 'asc');

        AdsQry = AdsQry.where('complete', '==', 'yes')
        //.where('countrycode', '==', 'IT')
        .orderBy('priceSort', 'desc')

    AdsQry.get().then(function(snapshot) {
      snapshot.forEach((doc) => {
        console.log(doc.id+": priceSort="+doc.data().priceSort+" dateSort="+doc.data().dateSort);
      })
    })

1 Answer 1

0

Have you tried doing it like so:

 AdsQry
    .where('GeoPoint', '>', locations.lesserGeopoint)
    .where('GeoPoint', '<', locations.greaterThan)
    .where('complete', '==', 'yes')
    //.where('countrycode', '==', 'IT')
    .orderBy('GeoPoint')
    .orderBy('priceSort', 'desc')

Here's a link to the documentation

5
  • Yes, still same result.. Please one can try it here as same as this, i want the index to order accordingly by numberic jsbin.com/dekafuvevo/1/edit?js,console Jul 23, 2018 at 18:07
  • Have you tried creating indexes for priceSort in the Firebase console? AFAIK in Firestore if you want to order by a field that isn't in your where statement, you need to create an index for both priceSort and GeoPoint Jul 25, 2018 at 14:17
  • No, i don't know about this option Jul 25, 2018 at 19:21
  • 1
    Take a look at composite indexes here Jul 25, 2018 at 20:05
  • Thanks for the efforts, but still same reponse. i decided switching to elasticsearch i was trying to avoid in the project Jul 25, 2018 at 21:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.