Skip to content

Instantly share code, notes, and snippets.

@nwaughachukwuma
Last active November 22, 2019 14:08
Show Gist options
  • Save nwaughachukwuma/28e1cb7760ce7c971a26574e71b43aa1 to your computer and use it in GitHub Desktop.
Save nwaughachukwuma/28e1cb7760ce7c971a26574e71b43aa1 to your computer and use it in GitHub Desktop.
/**
* Firestore now supports a where-in query on the admin SDK
*/
import admin from "../admin" // pre-initialised
// Instead of this
async function hasUserTraveledTo(listOfStates, userId) {
for (const state in listOfStates) {
const userHasTraveledTo = await admin.firestore().collection(`users/${userId}/travelDestinations`)
.where('state', '==', state)
.get()
if (!userHasTraveledTo.empty) {
return true
}
}
return false;
}
// Use this
async function hasUserTraveledTo(listOfStates, userId) {
const userHasTraveledTo = await admin.firestore().collection(`users/${userId}/travelDestinations`)
.where('state', 'in', listOfStates)
.get()
if (!userHasTraveledTo.empty) {
return true
}
return false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment