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);
      })
    })
General Omosco
  • 606
  • 1
  • 10
  • 20

1 Answers1

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

Rodrigo Mata
  • 1,779
  • 2
  • 14
  • 23
  • Yes, still same result.. Please one can try it here as same as this, i want the index to order accordingly by numberic https://jsbin.com/dekafuvevo/1/edit?js,console – General Omosco Jul 23 '18 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` – Rodrigo Mata Jul 25 '18 at 14:17
  • No, i don't know about this option – General Omosco Jul 25 '18 at 19:21
  • 1
    Take a look at [composite indexes here](https://firebase.google.com/docs/firestore/query-data/index-overview) – Rodrigo Mata Jul 25 '18 at 20:05
  • Thanks for the efforts, but still same reponse. i decided switching to elasticsearch i was trying to avoid in the project – General Omosco Jul 25 '18 at 21:03