在Firebase Firestore中使用外部排序而不使用使用的查询不等式

时间:2018-07-23 17:46:59

标签: firebase google-cloud-firestore geopoints inequality

无论如何,在这个位置上我是否可以逃脱GeoPoint的首要任务? 如果我从orderby中删除GeoPoint则触发以下错误,并且如果按照以下说明将GeoPoint设置为第一个orderby,则会误导第二个orderby priceSort。

  

未捕获的错误:无效的查询。你有一个where过滤器   在“ GeoPoint”字段上具有不等式(<,<=,>或> =),因此您   还必须使用“ GeoPoint”作为您的第一个Query.orderBy(),但您的第一个   Query.orderBy()放在字段“ priceSort”上。

 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 个答案:

答案 0 :(得分:0)

您是否尝试过这样做:

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

这里是link to the documentation