While going through Firebase’s documentation for geohashing,
Im using modular SDK, and I tried converting the namespace code,
but I was encountering a TypeError that q.get is not a function
// Find cities within Dkm of [lat, lng]
const center = [Number(lat), Number(lng)];
const radiusInM = dist * 1000;
// Each item in 'bounds' represents a startAt/endAt pair. We have to issue
// a separate query for each pair. There can be up to 9 pairs of bounds
// depending on overlap, but in most cases there are 4.
const bounds = geohashQueryBounds(center, radiusInM);
const promises = [];
for (const b of bounds) {
const q = query(
collection(db, USERS_COL),
orderBy('geohash'),
startAt(b[0]),
endAt(b[1])
);
promises.push(q.get());
}
Documentation code:
st radiusInM = 50 * 1000;
// Each item in 'bounds' represents a startAt/endAt pair. We have to issue
// a separate query for each pair. There can be up to 9 pairs of bounds
// depending on overlap, but in most cases there are 4.
const bounds = geofire.geohashQueryBounds(center, radiusInM);
const promises = [];
for (const b of bounds) {
const q = db.collection('cities')
.orderBy('geohash')
.startAt(b[0])
.endAt(b[1]);
promises.push(q.get());
}
2
Answers
Attaching the code, incase others fall into the issue too: I had to completely remove the get function, use getDoc(), save the snapshot of data, and then compare with the center, by for loop
I recommend keeping the Firebase documentation handy when doing a conversion like this, as it has code snippets for both the older syntax and the newer syntax side by side.
For example, the documentation on executing a query shows that the syntax in v9 is: