Firebase 如何将SQL转换为firestore查询
我有这样一个查询语句:Firebase 如何将SQL转换为firestore查询,firebase,google-cloud-firestore,database-schema,Firebase,Google Cloud Firestore,Database Schema,我有这样一个查询语句: SELECT * FROM Customers WHERE (@ID IS NULL OR ID = @ID) AND (@Name IS NULL OR Name = @Name) 但我不知道在firestore里用它。你能帮助我吗。谢谢你Firestore在查询中没有等价的或条件,至少不是你在这里使用的类型。这是一个作为和工作的查询,而不是OP所寻找的或。 // Create a reference to the cities collection var cRe
SELECT * FROM Customers WHERE (@ID IS NULL OR ID = @ID) AND (@Name IS NULL OR Name = @Name)
但我不知道在firestore里用它。你能帮助我吗。谢谢你Firestore在查询中没有等价的
或条件,至少不是你在这里使用的类型。这是一个作为和工作的查询,而不是OP所寻找的或。
// Create a reference to the cities collection
var cRef = db.collection("customers");
// Create a query against the collection.
var query = cRef.where("id", "in", [NULL,"YOURID"]).where("name", "in", [NULL,"YOURNAME"]);
query.get()
.then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
// doc.data() is never undefined for query doc snapshots
console.log(doc.id, " => ", doc.data());
});
})
.catch(function(error) {
console.log("Error getting documents: ", error);
});