我正在寻找关于firestore文档参考中查询函数的更多细节,我发现了这个伪语法:
query(query, queryConstraints)
,但是在所有firestore关于这个函数的例子中,他们在第一个参数中使用集合引用,而不是query
form firestore示例:
// Create a reference to the cities collection
import { collection, query, where } from "firebase/firestore";
const citiesRef = collection(db, "cities");
// Create a query against the collection.
const q = query(citiesRef, where("state", "==", "CA"));
是相同的函数还是它的另一个签名?
集合引用是查询的子类,因此无论API期望Query
,您也可以传递CollectionReference
。因此,您可以通过将CollectionReference
传递给query
函数来构建新的查询,或者通过将Query
传递给它来为现有查询添加条件。