问题
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