Using external orderby without using used query inequality in firebase firestore

半世苍凉 提交于 2020-01-02 12:09:05

问题


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:


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



来源:https://stackoverflow.com/questions/51484558/using-external-orderby-without-using-used-query-inequality-in-firebase-firestore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!