@firebase/firestore

功能

功能描述
函数(应用程序,...)
获取Firestore(应用程序)返回与提供的FirebaseApp关联的现有默认Firestore实例。如果不存在实例,则使用默认设置初始化新实例。
getFirestore(应用程序,数据库Id) (测试版)返回与提供的FirebaseApp关联的现有命名Firestore实例。如果不存在实例,则使用默认设置初始化新实例。
初始化Firestore(应用程序,设置,databaseId)使用提供的设置初始化Firestore的新实例。只能在任何其他函数之前调用,包括getFirestore() 。如果自定义设置为空,该函数相当于调用getFirestore()
函数(firestore,...)
清除IndexedDbPersistence(firestore)清除持久存储。这包括挂起的写入和缓存的文档。必须在Firestore实例未启动时(应用程序终止后或应用程序首次初始化时)调用。启动时,必须在其他函数( initializeFirestore()getFirestore()除外)之前调用此函数))。如果Firestore实例仍在运行,则 Promise 将被拒绝,错误代码为failed-precondition注意: clearIndexedDbPersistence()主要旨在帮助编写使用 Cloud Firestore 的可靠测试。它使用有效的机制来删除现有数据,但不会尝试安全地覆盖或以其他方式使缓存的数据无法恢复。对于对用户会话之间缓存数据的泄露敏感的应用程序,我们强烈建议根本不要启用持久性。
集合(firestore、路径、pathSegments)获取引用指定绝对路径处的集合CollectionReference实例。
集合组(firestore,集合Id)创建并返回一个新的Query实例,其中包含数据库中具有给定collectionId集合或子集合中包含的所有文档。
connectFirestoreEmulator(firestore、主机、端口、选项)修改此实例以与 Cloud Firestore 模拟器进行通信。注意:必须在使用该实例执行任何操作之前调用此方法。
禁用网络(firestore)禁用此实例的网络使用。可以通过enableNetwork()重新启用它。当网络被禁用时,任何快照侦听器、 getDoc()getDocs()调用都将从缓存返回结果,并且任何写入操作都将排队,直到网络恢复。
文档(firestore、路径、pathSegments)获取引用指定绝对路径处的文档的DocumentReference实例。
启用IndexedDbPersistence(firestore,persistenceSettings)如果可能,尝试启用持久存储。如果失败, enableIndexedDbPersistence()将拒绝承诺或抛出异常。失败的原因有多种,可以通过错误code来识别。 * 失败前提条件:应用程序已在另一个浏览器选项卡中打开。 * 未实现:浏览器与离线持久化实现不兼容。请注意,即使发生故障, Firestore实例仍将可用,但脱机持久性将被禁用。注意: enableIndexedDbPersistence()必须在任何其他函数( initializeFirestore()除外)之前调用getFirestore()clearIndexedDbPersistence()持久性不能在 Node.js 环境中使用。
启用MultiTabIndexedDbPersistence(firestore)如果可能,尝试启用多选项卡持久存储。如果在所有选项卡上启用,则所有操作共享对本地持久性的访问,包括跨所有连接的实例共享查询执行和延迟补偿本地文档更新。如果失败, enableMultiTabIndexedDbPersistence()将拒绝承诺或抛出异常。失败的原因有多种,可以通过错误code来识别。 * 失败前提条件:应用程序已在另一个浏览器选项卡中打开,并且未启用多选项卡。 * 未实现:浏览器与离线持久化实现不兼容。请注意,即使发生故障, Firestore实例仍将可用,但脱机持久性将被禁用。
启用网络(firestore)在先前调用disableNetwork()后重新启用此Firestore实例的网络使用
获取持久缓存索引管理器(firestore)返回给定Firestore对象使用的 PercientCache 索引管理器。 PersistentCacheIndexManager实例,如果未使用本地持久存储,则为null
loadBundle(firestore,bundleData)将 Firestore 捆绑包加载到本地缓存中。
命名查询(firestore,名称)从本地缓存读取由给定名称标识的 Firestore查询命名查询在服务器端打包成捆绑包(以及生成的文档),并使用loadBundle加载到本地缓存。进入本地缓存后,使用此方法按名称提取查询
onSnapshotsInSync(firestore,观察者)附加快照同步事件的侦听器。 snapshots-in-sync 事件表示受给定更改影响的所有侦听器均已触发,即使单个服务器生成的更改会影响多个侦听器。注意:snapshots-in-sync 事件仅指示侦听器彼此同步,但与这些快照是否与服务器同步无关。在各个侦听器中使用 SnapshotMetadata 来确定快照是来自缓存还是来自服务器。
onSnapshotsInSync(firestore,onSync)附加快照同步事件的侦听器。 snapshots-in-sync 事件表示受给定更改影响的所有侦听器均已触发,即使单个服务器生成的更改会影响多个侦听器。注意:snapshots-in-sync 事件仅指示侦听器彼此同步,但与这些快照是否与服务器同步无关。在各个侦听器中使用SnapshotMetadata来确定快照是来自缓存还是来自服务器。
runTransaction(firestore,updateFunction,选项)执行给定的updateFunction ,然后尝试提交事务中应用的更改。如果事务中读取的任何文档发生更改,Cloud Firestore 会重试updateFunction 。如果5次尝试后仍无法提交,则事务失败。单个事务允许的最大写入次数为 500。
setIndexConfiguration(firestore,配置) (测试版)配置本地查询执行的索引。任何以前的索引配置都将被覆盖。一旦索引配置被持久化, Promise就会解析。索引条目本身是异步创建的。即使索引尚不可用,您也可以继续使用需要索引的查询。一旦写入索引条目,查询执行将自动开始使用索引。仅 IndexedDb 持久性支持索引。如果未启用 IndexedDb,则任何索引配置都会被忽略。
setIndexConfiguration(firestore,json) (测试版)配置本地查询执行的索引。任何以前的索引配置都将被覆盖。一旦索引配置被持久化, Promise就会解析。索引条目本身是异步创建的。即使索引尚不可用,您也可以继续使用需要索引的查询。一旦写入索引条目,查询执行将自动开始使用索引。仅 IndexedDb 持久性支持索引。在设置索引配置之前调用enableIndexedDbPersistence()enableMultiTabIndexedDbPersistence() 。如果未启用 IndexedDb,则任何索引配置都会被忽略。该方法接受 Firebase CLI ( firebase firestore:indexes ) 导出的 JSON 格式。如果 JSON 格式无效,此方法将引发错误。
终止(火存储)终止提供的Firestore实例。调用terminate()后,只能使用clearIndexedDbPersistence()函数。任何其他函数都会抛出FirestoreError要在终止后重新启动,请使用getFirestore()创建 FirebaseFirestore 的新实例终止不会取消任何挂起的写入,并且任何等待服务器响应的承诺都不会得到解决。如果您启用了持久性,则下次启动此实例时,它将继续将这些写入发送到服务器。注意:一般情况下,不需要调用terminate() 。仅当您想要强制此实例释放其所有资源或与clearIndexedDbPersistence()结合使用以确保在测试运行之间销毁所有本地状态时,此函数才有用。
waitForPendingWrites(firestore)等待,直到后端确认活动用户的所有当前挂起的写入。如果没有未完成的写入,则返回的承诺将立即解决。否则,promise 将等待所有先前发出的写入(包括在先前应用程序会话中写入的写入),但它不会等待调用函数后添加的写入。如果您想等待其他写入,请再次调用waitForPendingWrites()在用户更改期间,任何未完成的waitForPendingWrites()承诺都会被拒绝。
writeBatch(火存储)创建一个写入批处理,用于将多个写入作为单个原子操作执行。单个WriteBatch中允许的最大写入次数为 500。与事务不同,写入批次会离线保存,因此当您不需要根据读取数据调整写入时更可取。
功能()
数数()创建一个 AggregateField 对象,该对象可用于计算查询结果集中的文档计数。
删除字段()返回一个哨兵,与带有{merge: true}updateDoc()setDoc()一起使用,以标记要删除的字段。
文档ID()返回一个特殊的哨兵FieldPath来引用文档的 ID。它可用于在查询中按文档 ID 排序或过滤。
获取Firestore()返回与默认FirebaseApp关联的现有默认Firestore实例。如果不存在实例,则使用默认设置初始化新实例。
内存EagerGarbageCollector()创建MemoryEagerGarbageCollector的实例。这也是默认的垃圾收集器,除非另有明确指定。
持久化多个选项卡管理器()创建PersistentMultipleTabManager的实例。
服务器时间戳()返回与setDoc()updateDoc()一起使用的哨兵,以在写入的数据中包含服务器生成的时间戳。
函数(数据库ID,...)
getFirestore(数据库ID) (测试版)返回与默认FirebaseApp关联的现有命名Firestore实例。如果不存在实例,则使用默认设置初始化新实例。
函数(元素,...)
数组删除(元素)返回一个可以与setDoc()一起使用的特殊值,或者告诉服务器从服务器上已存在的任何数组值中删除给定元素。指定的每个元素的所有实例都将从数组中删除。如果正在修改的字段还不是数组,它将被空数组覆盖。
数组联合(元素)返回一个可以与setDoc()updateDoc()一起使用的特殊值,该值告诉服务器将给定元素与服务器上已存在的任何数组值联合起来。数组中尚不存在的每个指定元素都将添加到末尾。如果正在修改的字段还不是数组,它将被包含确切指定元素的数组覆盖。
函数(字段,...)
平均(场)创建一个 AggregateField 对象,该对象可用于计算查询结果集中一系列文档中指定字段的平均值。
总和(字段)创建一个 AggregateField 对象,该对象可用于计算查询结果集中一系列文档的指定字段的总和。
函数(字段路径,...)
orderBy(fieldPath, 方向Str)创建一个QueryOrderByConstraint ,按指定字段对查询结果进行排序,可以选择按降序而不是升序。注意:不包含指定字段的文档不会出现在查询结果中。
其中(字段路径、opStr、值)创建一个QueryFieldFilterConstraint ,强制文档必须包含指定字段并且该值应满足提供的关系约束。
函数(字段值,...)
结束于(字段值)创建一个QueryEndAtConstraint ,它将结果集修改为相对于查询顺序在提供的字段处结束。字段值的顺序必须与查询的 order by 子句的顺序匹配。
结束之前(字段值)创建一个QueryEndAtConstraint ,将结果集修改为相对于查询顺序在提供的字段之前结束。字段值的顺序必须与查询的 order by 子句的顺序匹配。
开始之后(字段值)创建一个QueryStartAtConstraint ,它将结果集修改为相对于查询顺序在提供的字段之后开始。字段值的顺序必须与查询的 order by 子句的顺序匹配。
开始于(字段值)创建一个QueryStartAtConstraint ,它将结果集修改为从相对于查询顺序提供的字段开始。字段值的顺序必须与查询的 order by 子句的顺序匹配。
函数(索引管理器,...)
删除所有持久缓存索引(indexManager)删除所有持久缓存索引。请注意,此函数还将删除由setIndexConfiguration()生成的索引,该索引已被弃用。
禁用PersistentCacheIndexAutoCreation(indexManager)停止自动为本地查询执行创建持久缓存索引。通过调用enablePersistentCacheIndexAutoCreation()创建的索引仍然有效。
启用持久缓存索引自动创建(indexManager)当 SDK 认为缓存索引有助于提高性能时,使 SDK 能够自动为本地查询执行创建持久缓存索引。默认情况下禁用此功能。
函数(左,...)
聚合字段等于(左,右)比较两个“AggregateField” ` 平等的实例。
聚合查询快照等于(左,右)比较两个AggregateQuerySnapshot实例是否相等。如果两个AggregateQuerySnapshot实例具有比较相等且数据相同的基础查询,则它们被视为“相等”。
查询等于(左,右)如果提供的查询指向同一集合并应用相同的约束,则返回 true。
refEqual(左,右)如果提供的引用相等,则返回 true。
快照等于(左,右)如果提供的快照相等,则返回 true。
函数(极限,...)
限制(限制)创建一个仅返回第一个匹配文档的QueryLimitConstraint
限制到最后(限制)创建一个仅返回最后匹配文档的QueryLimitConstraint limitToLast查询必须至少指定一个orderBy子句,否则执行过程中会抛出异常。
函数(日志级别,...)
设置日志级别(日志级别)设置 Cloud Firestore 日志的详细程度(调试、错误或静默)。
函数(n,...)
增量(n)返回一个特殊值,可与setDoc()updateDoc()一起使用,告诉服务器将字段的当前值增加给定值。如果操作数或当前字段值使用浮点精度,则所有算术都遵循 IEEE 754 语义。如果两个值都是整数,则超出 JavaScript 安全数字范围( Number.MIN_SAFE_INTEGERNumber.MAX_SAFE_INTEGER )的值也会受到精度损失的影响。此外,一旦由 Firestore 后端处理,所有整数运算都限制在 -2^63 和 2^63-1 之间。如果当前字段值不是number类型,或者该字段尚不存在,则转换会将该字段设置为给定值。
函数(查询,...)
getAggregateFromServer(查询,aggregateSpec)计算给定查询结果集中文档的指定聚合,而无需实际下载文档。使用此函数执行聚合非常高效,因为仅下载最终聚合值,而不下载文档数据。当结果集太大而无法完全下载(数千个文档)时,此函数可以执行文档聚合。从服务器接收到的结果将保持不变,不考虑任何本地状态。也就是说,不考虑本地缓存中的文档,也不考虑尚未与服务器同步的本地修改。不使用以前下载的结果(如果有)。该函数的每次调用都必然涉及到服务器的往返。
从服务器获取计数(查询)计算给定查询的结果集中的文档数,而无需实际下载文档。使用此功能对文档进行计数非常高效,因为只下载最终计数,而不下载文档数据。当结果集太大而无法完全下载(数千个文档)时,此函数可以对文档进行计数。从服务器接收到的结果将保持不变,不考虑任何本地状态。也就是说,不考虑本地缓存中的文档,也不考虑尚未与服务器同步的本地修改。不使用以前下载的结果(如果有)。该函数的每次调用都必然涉及到服务器的往返。
获取文档(查询)执行查询并将结果作为QuerySnapshot返回。注意: getDocs()尝试通过等待来自服务器的数据来提供最新数据,但如果您处于离线状态并且无法访问服务器,它可能会返回缓存的数据或失败。要指定此行为,请调用getDocsFromCache()getDocsFromServer()
从缓存中获取文档(查询)执行查询并从缓存中以QuerySnapshot形式返回结果。如果当前没有缓存与查询匹配的文档,则返回空结果集。
从服务器获取文档(查询)执行查询并将结果作为QuerySnapshot从服务器返回。如果网络不可用,则返回错误。
onSnapshot(查询,观察者)附加QuerySnapshot事件的侦听器。您可以传递单独的onNextonError回调,也可以传递带有nexterror回调的单个观察者对象。可以通过调用onSnapshot时返回的函数来取消监听。注意:虽然可以提供onCompletion回调,但它永远不会被调用,因为快照流是永无止境的。
onSnapshot(查询、选项、观察者)附加QuerySnapshot事件的侦听器。您可以传递单独的onNextonError回调,也可以传递带有nexterror回调的单个观察者对象。可以通过调用onSnapshot时返回的函数来取消监听。注意:虽然可以提供onCompletion回调,但它永远不会被调用,因为快照流是永无止境的。
onSnapshot(查询、onNext、onError、onCompletion)附加QuerySnapshot事件的侦听器。您可以传递单独的onNextonError回调,也可以传递带有nexterror回调的单个观察者对象。可以通过调用onSnapshot时返回的函数来取消监听。注意:虽然可以提供onCompletion回调,但它永远不会被调用,因为快照流是永无止境的。
onSnapshot(查询、选项、onNext、onError、onCompletion)附加QuerySnapshot事件的侦听器。您可以传递单独的onNextonError回调,也可以传递带有nexterror回调的单个观察者对象。可以通过调用onSnapshot时返回的函数来取消监听。注意:虽然可以提供onCompletion回调,但它永远不会被调用,因为快照流是永无止境的。
查询(查询、复合过滤器、查询约束)创建一个新的不可变Query实例,该实例已扩展为还包含其他查询约束。
查询(查询,查询约束)创建一个新的不可变Query实例,该实例已扩展为还包含其他查询约束。
函数(查询约束,...)
和(查询约束)创建一个新的QueryCompositeFilterConstraint ,它是给定过滤器约束的结合。如果合取过滤器满足所有给定过滤器,则该文档包含该文档。
或(查询约束)创建一个新的QueryCompositeFilterConstraint ,它是给定过滤器约束的析取。如果析取过滤器满足任何给定过滤器,则该文档包含该文档。
函数(参考,...)
addDoc(参考,数据)使用给定数据将新文档添加到指定的CollectionReference ,并自动为其分配文档 ID。
集合(参考、路径、pathSegments)获取一个CollectionReference实例,该实例引用指定相对路径处的reference子集合。
集合(参考、路径、pathSegments)获取一个CollectionReference实例,该实例引用指定相对路径处的reference子集合。
删除文档(参考)删除指定DocumentReference引用的文档。
文档(参考、路径、路径段)获取一个DocumentReference实例,该实例引用指定相对路径处的reference内的文档。如果未指定路径,则返回的DocumentReference将使用自动生成的唯一 ID。
文档(参考、路径、路径段)获取一个DocumentReference实例,该实例引用指定相对路径处的reference内的文档。
获取文档(参考)读取此DocumentReference引用的文档。注意: getDoc()尝试通过等待来自服务器的数据来提供最新数据,但如果您处于离线状态并且无法访问服务器,它可能会返回缓存的数据或失败。要指定此行为,请调用getDocFromCache()getDocFromServer()
getDocFromCache(参考)从缓存中读取此DocumentReference引用的文档。如果当前未缓存文档,则返回错误。
从服务器获取文档(参考)从服务器读取此DocumentReference引用的文档。如果网络不可用,则返回错误。
onSnapshot(参考,观察者)附加DocumentSnapshot事件的侦听器。您可以传递单独的onNextonError回调,也可以传递带有nexterror回调的单个观察者对象。注意:虽然可以提供onCompletion回调,但它永远不会被调用,因为快照流是永无止境的。
onSnapshot(参考,选项,观察者)附加DocumentSnapshot事件的侦听器。您可以传递单独的onNextonError回调,也可以传递带有nexterror回调的单个观察者对象。注意:虽然可以提供onCompletion回调,但它永远不会被调用,因为快照流是永无止境的。
onSnapshot(参考、onNext、onError、onCompletion)附加DocumentSnapshot事件的侦听器。您可以传递单独的onNextonError回调,也可以传递带有nexterror回调的单个观察者对象。注意:虽然可以提供onCompletion回调,但它永远不会被调用,因为快照流是永无止境的。
onSnapshot(参考,选项,onNext,onError,onCompletion)附加DocumentSnapshot事件的侦听器。您可以传递单独的onNextonError回调,也可以传递带有nexterror回调的单个观察者对象。注意:虽然可以提供onCompletion回调,但它永远不会被调用,因为快照流是永无止境的。
setDoc(参考,数据)写入此DocumentReference引用的文档。如果该文档尚不存在,则会创建该文档。
setDoc(参考、数据、选项)写入指定DocumentReference引用的文档。如果该文档尚不存在,则会创建该文档。如果您提供mergemergeFields ,则提供的数据可以合并到现有文档中。
updateDoc(参考,数据)更新指定DocumentReference引用的文档中的字段。如果应用于不存在的文档,更新将会失败。
updateDoc(参考、字段、值、moreFieldsAndValues)更新指定DocumentReference引用的文档中的字段 如果应用于不存在的文档,更新将失败。可以通过提供点分隔的字段路径字符串或提供FieldPath对象来更新嵌套字段。
功能(设置,...)
内存本地缓存(设置)创建MemoryLocalCache的实例。该实例可以设置为FirestoreSettings.cache来告诉 SDK 使用哪个缓存层。
内存LruGarbageCollector(设置)创建MemoryLruGarbageCollector的实例。目标尺寸可以指定为设置参数的一部分。一旦缓存大小超过给定大小,收集器将开始删除文档。默认缓存大小为 40MB(40 * 1024 * 1024 字节)。
持久本地缓存(设置)创建PersistentLocalCache的实例。该实例可以设置为FirestoreSettings.cache来告诉 SDK 使用哪个缓存层。持久缓存不能在 Node.js 环境中使用。
持久单标签管理器(设置)创建PersistentSingleTabManager的实例。
函数(快照,...)
结束时间(快照)创建一个QueryEndAtConstraint ,将结果集修改为以提供的文档(包含)结束。结束位置与查询的顺序相关。该文档必须包含查询的 orderBy 中提供的所有字段。
结束之前(快照)创建一个QueryEndAtConstraint ,将结果集修改为在提供的文档之前结束(不包括)。结束位置与查询的顺序相关。该文档必须包含查询的 orderBy 中提供的所有字段。
开始之后(快照)创建一个QueryStartAtConstraint ,将结果集修改为在提供的文档之后开始(不包括)。起始位置与查询的顺序相关。该文档必须包含查询的 orderBy 中提供的所有字段。
开始时间(快照)创建一个QueryStartAtConstraint ,它将结果集修改为从提供的文档(包括)开始。起始位置与查询的顺序相关。该文档必须包含此查询的orderBy中提供的所有字段。

课程

班级描述
聚合字段表示可由 Firestore 执行的聚合。
聚合查询快照执行聚合查询的结果。
字节表示字节数组的不可变对象。
收藏参考CollectionReference对象可用于添加文档、获取文档引用和查询文档(使用query() )。
文档参考DocumentReference是指 Firestore 数据库中的文档位置,可用于写入、读取或侦听该位置。引用位置处的文档可能存在,也可能不存在。
文档快照DocumentSnapshot包含从 Firestore 数据库中的文档读取的数据。可以使用.data().get(<field>)提取数据以获取特定字段。对于指向不存在文档的DocumentSnapshot ,任何数据访问都将返回“未定义”。您可以使用exists()方法显式验证文档是否存在。
字段路径FieldPath指的是文档中的字段。该路径可以由单个字段名称(指文档中的顶级字段)或字段名称列表(指文档中的嵌套字段)组成。通过提供字段名称创建FieldPath 。如果提供多个​​字段名称,则路径将指向文档中的嵌套字段。
字段值使用set()update()写入文档字段时可以使用的哨兵值。
火库Cloud Firestore 服务接口。不要直接调用此构造函数。相反,使用getFirestore()
Firestore错误Firestore 操作返回的错误。
地理点表示 Firestore 中地理位置的不可变对象。该位置以纬度/经度对表示。纬度值的范围为 [-90, 90]。经度值的范围为 [-180, 180]。
加载Bundle任务表示加载 Firestore 捆绑包的任务。它提供包加载的进度,以及任务完成和错误事件。该 API 与Promise<LoadBundleTaskProgress>兼容。
持久缓存索引管理器PersistentCacheIndexManager ,用于配置用于本地查询执行的持久缓存索引。使用时,调用getPersistentCacheIndexManager()来获取一个实例。
询问Query是指您可以阅读或收听的查询。您还可以通过添加过滤器和排序来构造精炼的Query对象。
查询复合过滤器约束QueryCompositeFilterConstraint用于通过执行多个QueryFieldFilterConstraint的逻辑 OR 或 AND 来缩小 Firestore 查询返回的文档集s 或QueryCompositeFilterConstraint s。 QueryCompositeFilterConstraint通过调用or()and()创建,然后可以传递给query()以创建也包含QueryCompositeFilterConstraint的新查询实例。
查询约束QueryConstraint用于缩小 Firestore 查询返回的文档集。 QueryConstraint通过调用where()创建, orderBy() ,开始处() ,开始之后() ,结束之前() ,结束 ()限制()limitToLast()然后可以传递给query()以创建一个也包含此QueryConstraint的新查询实例。
查询文档快照QueryDocumentSnapshot包含作为查询的一部分从 Firestore 数据库中的文档读取的数据。该文档保证存在,并且可以使用.data().get(<field>)提取其数据以获取特定字段。 QueryDocumentSnapshot提供与DocumentSnapshot相同的 API 界面。由于查询结果仅包含现有文档, exists属性将始终为 true,并且data()永远不会返回“未定义”。
查询结束约束QueryEndAtConstraint用于从 Firestore 查询返回的结果集末尾排除文档。 QueryEndAtConstraint是通过调用endAt()endBefore()创建的,然后可以传递给query()以创建也包含此QueryEndAtConstraint的新查询实例。
查询字段过滤约束QueryFieldFilterConstraint用于通过过滤一个或多个文档字段来缩小 Firestore 查询返回的文档集。 QueryFieldFilterConstraint是通过调用where()创建的,然后可以传递给query()以创建一个也包含此QueryFieldFilterConstraint的新查询实例。
查询限制约束QueryLimitConstraint用于限制 Firestore 查询返回的文档数量。 QueryLimitConstraint是通过调用limit()limitToLast()创建的,然后可以传递给query()以创建一个也包含此QueryLimitConstraint的新查询实例。
按约束查询顺序QueryOrderByConstraint用于对 Firestore 查询返回的文档集进行排序。 QueryOrderByConstraint是通过调用ording Byboint()创建的,然后可以传递到Query()创建一个新的查询实例,该实例还包含此QueryOrderByConstraint注意:不包含订单字段的文档将在查询结果中不存在。
querysnapshot QuerySnapshot包含代表查询结果的零或更多DocumentSnapshot对象。可以通过docs属性作为数组访问文档,也可以使用forEach方法列举。文档数量可以通过emptysize属性确定。
querystartatconstraint从firestore查询返回的结果集的开始之初,使用QueryStartAtConstraint排除文档。通过调用startat()startafter()创建QueryStartAtConstraint s,然后可以传递到query()创建一个新的查询实例,其中还包含此QueryStartAtConstraint
快照元数据关于快照的元数据,描述了快照的状态。
时间戳Timestamp代表一个与任何时区或日历无关的时间点,在UTC时期的纳秒分辨率时表示为秒和秒的秒数。它是使用Proleptic Gregorian日历编码的,该日历将Gregorian日历向后扩展到第一年。它是编码的,假设所有分钟长60秒长,即leap秒是“涂抹”的,因此不需要leap第二张桌子来解释。范围从0001-01-01T00:00:00:00 Z到9999-12-31T23:59:59.99999999999Z。有关示例和其他规格,请参阅时间戳定义
交易对交易的引用。 Transaction对象传递给事务的updateFunction提供了在事务上下文中读取和写入数据的方法。请参阅RunTransaction()
写批处理写入批处理,用于将多个写入作为单个原子单元执行。可以通过调用writebatch()来获取WriteBatch对象。它提供了将写入添加到写入批次的方法。在调用writeBatch.commit()之前,任何写作都不会提交(或本地可见)。

接口

界面描述
聚集指定一组聚合及其别名。
DocumentChange DocumentChange表示与查询匹配的文档的更改。它包含受影响的文档和发生的更改类型。
DocumentData文档数据(与setDoc()一起使用)由映射到值的字段组成。
实验隆起使用长时间播放时配置SDK基础网络传输(网络渠)的选项。注意:此界面是“实验性的”,可能会发生变化。请参阅FirestoreSettings.experimentalAutoDetectLongPollingFirestoreSettings.experimentalForceLongPollingFirestoreSettings.experimentalLongPollingOptions
FirestoredAtaconverter withConverter()使用的转换器将类型AppModelType的用户对象转换为DbModelType类型的firestore数据。使用转换器可让您在Firestore中存储和检索对象时指定通用类型参数。在这种情况下,“ appModel”是一个在应用程序中用于包装相关信息和功能的类。例如,这样的类可以具有具有复杂,嵌套的数据类型的属性,用于记忆的属性,Firestore不支持的类型的属性(例如symbolbigint )以及执行复合操作的辅助功能。此类类不合适和/或可以存储到Firestore数据库中。取而代之的是,此类类的实例需要转换为具有原始属性的“普通旧JavaScript对象”(POJOS),可能嵌套在其他Pojos或Pojos的阵列中。在这种情况下,这种类型被称为“ dbModel”,将是一个适合持续进入firestore的对象。为了方便起见,应用程序可以实现FirestoreDataConverter并在存储到firestore时自动将AppModel转换为DocumentReference ,并在Firestore中自动将转换器注册,并从Firestore回收时将AppModel转换为DbModelQuery DbModel转换为AppModel
Firestoresettings为您的云Firestore实例指定自定义配置。您必须在调用任何其他方法之前设置这些设置。
指数(beta) Firestore索引的SDK定义。
索引配置(beta)一份firestore索引列表,以加快本地查询执行。有关索引定义格式的描述,请参见JSON格式
indexfield (beta)索引配置中的一个字段元素。
LoadBundLetask Progress代表加载捆绑包的进度更新或最终状态。
记忆塞术设置对象配置MemoryLocalCache实例。
MemoryEagergarbageCollector只要垃圾收集器不属于任何有效查询,并且没有附加局部突变。该收集器试图确保SDK的最低内存足迹,其风险没有被缓存以进行离线查询或直接查询缓存。使用工厂功能创建此收集器的实例。
MOMEMELOCALCACHE为SDK提供内存中缓存。除非另有明确配置,否则这是默认缓存。要使用,请使用工厂函数创建一个实例,然后将实例设置为FirestoreSettings.cache ,然后使用设置对象调用initializeFirestore
MOMEMELRUGARBAGECOLLECOR一个垃圾收集器删除了多批次最少使用的文档。该收集器配置为目标大小,并且只有在缓存文档超过目标大小时才执行收集。它避免了对同一查询或文档重复重复的查询后端,冒着更大的内存足迹的风险。使用工厂功能创建此收集器的实例。
持久性可以传递的设置enableIndexedDbPersistence()以配置Firestore持久性。持久性不能用于node.js环境中。
持续的塞术设置对象配置PersistentLocalCache实例。持续的缓存不能在node.js环境中使用。
PersistentLocalCache提供一个由索引的持续缓存到SDK。要使用,请使用工厂函数创建一个实例,然后将实例设置为FirestoreSettings.cache ,然后使用设置对象调用initializeFirestore
PersistentMultipletabManager支持多个选项卡的选项卡管理器。 SDK将使用SDK在所有选项卡上同步查询和突变。
持久性商人仅支持一个选项卡的选项卡管理器,将不同步在跨选项卡中执行。
持久性属于managersettings键入配置PersistentSingleTabManager实例。
Snapshotlistenoptions可以传递到onsnapshot()querysnapshot.docchanges()的选项对象,以控制结果集中包含哪些类型的更改。
快照配置如何从DocumentSnapshot检索数据的选项(例如,尚未将其设置为最终值设置为服务器时间戳的所需行为)。
交易定制交易行为的选项。
退订onSnapshot()返回的函数,该函数在调用时会删除侦听器。

变量

多变的描述
cache_size_unlimited用于指示LRU垃圾收集的常数。将此值设置为传递给Firestore实例的设置上的cacheSizeBytes

类型别名

类型别名描述
addprefixtokeys返回一个新的地图,其中每个键都在附加到点的外键前缀。
汇总FieldType Firestore支持的所有AggregateField类型的结合。
骨料pecdataAggregateSpec中获取的键的类型,其值是由相应的AggregateField从输入AggregateSpec执行的聚合的结果。
聚合类型代表要执行的聚合类型的联合类型。
Childupdatefields用于计算给定T1的嵌套字段的助手。这是分发联合类型(例如undefined | {...}所需的。 undefined | {...} (用于可选的道具发生)或{a: A} | {b: B}在此用例中, V用于RecordT[K]的联合类型,因为T[K]被评估为表达式而不是分布。请参阅https://www.typescriptlang.org/docs/handbook/advanced-types.html#distribnation-conditional-types
DocumentChangeType可以“添加”,“删除”或“修改”的DocumentChange的类型。
firestoreErrorCode Firestore状态代码集。 grpc在此处暴露的代码是相同的:可能的值: - “取消”:操作已取消(通常由呼叫者)。 - “未知”:未知错误或来自其他错误域的错误。 - “无效 - argument”:客户端指定了一个无效的参数。请注意,这不同于“失败至关”。 “无效的题词”指出了有问题的参数,无论系统状态如何(例如,字段名称无效)。 - “截止日期”:截止日期在操作完成之前已过期。对于更改系统状态的操作,即使操作成功完成,也可以返回此错误。例如,服务器的成功响应可能已经延迟了足够长的时间,以使截止日期到期。 - 'NOTUNDONG':找不到一些要求的文件。 - “已经存在的”:我们尝试创建的一些文档已经存在。 - “限制权限”:呼叫者无权执行指定的操作。 - “资源 - 偏项”:某些资源已经用尽,可能是每个用户配额,或者整个文件系统都超出了空间。 - “失败至上”:操作被拒绝,因为该系统不处于操作执行所需的状态。 - “中止”:该操作被中止,通常是由于交易中止等并发问题。-“ Out-range':Operation':操作已超过有效范围。 - '未完成':未实现或不支持/启用操作。 - '内部':内部错误。意味着某些基本系统预期的不变性已被打破。如果您看到这些错误之一,那么某些事情就会非常损坏。 - “不可用”:该服务目前不可用。这很可能是瞬态条件,可以通过退缩重试纠正。 - “数据损失”:无法恢复的数据丢失或损坏。 - “未经验证”:该请求没有对操作的有效身份验证凭证。
firestorelocalcache来自所有受支持的SDK缓存层的联合类型。
Liscensource描述询问来源的来源。设置为default以收听缓存和服务器更改。设置为cache以收听缓存的更改。
MemoryGarbageCollector所有支持Gabage收集器的联合类型用于内存本地缓存。
Nestedupdatefields对于每个字段(例如'bar'),找到所有嵌套键(例如{ 'bar.baz':t1,'bar.qux':t2 } )。将它们相交在一起,制作一个包含所有可能标记为可选的键的单个地图
OrderByDiriend订单()子句的方向指定为“ desc”或“ asc”(降序或上升)。
partialwithfieldValue类似于Typescript的Partial<T> ,但允许省略嵌套字段,并以属性值的形式传递字段值。
PersistentTabManager所有可用标签经理的结合。
原始原始类型。
QueryConstraintType描述此SDK中可用的不同查询约束。
QueryFilterConstraint QueryFilterConstraint是一种辅助联合类型,代表QueryFieldFilterConstraintQueryCompositeFilterConstraint
querynonfilterconstraint QueryNonFilterConstraint是一种辅助联合类型,代表用于缩小或订购一组文档的QueryConstraints,但不会在文档字段上明确过滤。 QueryNonFilterConstraint是通过调用Order Boildboint()创建的startat()startafter()endbefore()endat()limit()limittolast() ,然后可以传递到query()创建一个新的查询实例,该实例还包含QueryConstraint
设置选项配置setDoc()行为的选项对象,并打电话。这些调用可以配置为执行颗粒状合并,而不是通过提供合并的SetOptions merge: true来整体覆盖目标文档。
TaskState表示捆绑加载任务的状态。 “错误”和“成功”都处于沉没状态:任务将中止或完成,并且报告后将不再有更新。
联合助力给定一个Union Type U = T1 | T2 | ... ,返回相交类型(T1 & T2 & ...)使用有条件类型的分配条件类型和推断。之所以起作用,是因为相反位置中相同类型变量的多个候选物会导致相交类型。 https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-in​​perionpe-in​​perion-inperion-in-conditional-types https://stackoverflow.com/questions/questions/50374908/trans-trans-form-type-type-type-type-type-type-in​​tercection -类型
更新更新数据(用于UpdatedOc() )由映射到值的野外路径(例如'foo'或'foo.baz')组成。包含DOT的字段参考文档中的嵌套字段。字段值可以作为属性值传递。
filterop使用字符串' lt;','&lt; =','==','!=','&gt; =',','&gt;','array-contains',使用字符串'&lt; =','==',',',',',',',',',',',',',',',',',',',',',',',',',! ,“ in”,“ array-contains-”和“ Not-In”。
与FieldValue在维持类型安全性的同时,允许将现场价值作为属性值传递。

功能(应用,...)

getfirestore(app)

返回与提供的FirebaseApp关联的现有默认firestore实例。如果不存在实例,请用默认设置初始化一个新实例。

签名:

export declare function getFirestore(app: FirebaseApp): Firestore;

参数

范围类型描述
应用程序Firebase应用程序返回的firestore实例与之关联的firebaseApp实例。

返回:

火库

提供的应用程序的默认firestore实例。

getfirestore(应用程序,数据库)

此API是作为开发人员的预览提供的,可能会根据我们收到的反馈而更改。不要在生产环境中使用此API。

返回与提供的firebaseApp关联的现有命名的firestore实例。如果不存在实例,请用默认设置初始化一个新实例。

签名:

export declare function getFirestore(app: FirebaseApp, databaseId: string): Firestore;

参数

范围类型描述
应用程序Firebase应用程序返回的firestore实例与之关联的firebaseApp实例。
数据库细绳数据库的名称。

返回:

火库

提供的应用程序的命名firestore实例。

InitializeFirestore(应用程序,设置,数据库)

用提供的设置初始化Firestore的新实例。只能在任何其他功能之前都调用,包括getfirestore() 。如果自定义设置为空,则此功能等于调用getfirestore()

签名:

export declare function initializeFirestore(app: FirebaseApp, settings: FirestoreSettings, databaseId?: string): Firestore;

参数

范围类型描述
应用程序Firebase应用程序Firestore实例相关联的FirebaseApp
设置Firestoresettings设置对象以配置firestore实例。
数据库细绳数据库的名称。

返回:

火库

新初始化的Firestore实例。

功能(Firestore,...)

clearIndexedDbpersistence(firestore)

清除持续存储。这包括等待写作和缓存文件。

必须在未启动Firestore实例时(在应用程序终止或首次初始化应用程序时)时调用。在启动时,必须在其他函数之前调用此功能(除了初始化firestore()getfirestore()() ))。如果Firestore实例仍在failed-precondition

签名:

export declare function clearIndexedDbPersistence(firestore: Firestore): Promise<void>;

参数

范围类型描述
火库火库Firestore实例要清除持久性。

返回:

承诺<无效>

清除持久存储时解决的Promise将得到解决。否则,承诺将被错误拒绝。

收集(Firestore,Path,Pathsegments)

获取一个CollectionReference实例,该实例指定的绝对路径处的集合。

签名:

export declare function collection(firestore: Firestore, path: string, ...pathSegments: string[]): CollectionReference<DocumentData, DocumentData>;

参数

范围类型描述
火库火库对根Firestore实例的引用。
小路细绳以斜线分隔的集合路径。
路径细绳[]相对于第一个参数适用的其他路径段。

返回:

收藏参考< DocumentDataDocumentData >

CollectionReference实例。

例外情况

如果最终路径具有均匀数的段,并且没有指向集合。

CollectionGroup(Firestore,CollectionID)

创建并返回一个新的Query实例,其中包含数据库中包含的所有文档,该实例包含在集合中或带有给定collectionId的子集合中

签名:

export declare function collectionGroup(firestore: Firestore, collectionId: string): Query<DocumentData, DocumentData>;

参数

范围类型描述
火库火库对根Firestore实例的引用。
CollectionID细绳标识要查询的集合。将包含将此 ID 作为其路径最后一段的每个集合或子集合。不能包含斜杠。

返回:

询问< DocumentDataDocumentData >

创建的Query

ConnectFirestoreEmulator(Firestore,Host,端口,选项)

修改此实例以与Cloud Firestore模拟器进行通信。

签名:

export declare function connectFirestoreEmulator(firestore: Firestore, host: string, port: number, options?: {
    mockUserToken?: EmulatorMockTokenOptions | string;
}): void;

参数

范围类型描述
火库火库要配置以连接模拟器的Firestore实例。
主持人细绳模拟器主机(例如:localhost)。
港口数字模拟器端口(例如:9000)。
选项{oibusertoken?: eMulatorMockTokenOptions |细绳; }

返回:

空白

残疾人(Firestore)

禁用此实例的网络使用。它可以通过enablenetwork()重新启用。在禁用网络时,任何快照侦听器, getDoc()getDocs()调用将返回缓存的结果,并且任何写操作都将排队直到恢复网络。

签名:

export declare function disableNetwork(firestore: Firestore): Promise<void>;

参数

范围类型描述
火库火库

返回:

承诺<无效>

一旦网络被禁用,就可以解决的Promise

DOC(Firestore,Path,Pathsegments)

获取一个DocumentReference实例,该实例涉及指定的绝对路径上的文档。

签名:

export declare function doc(firestore: Firestore, path: string, ...pathSegments: string[]): DocumentReference<DocumentData, DocumentData>;

参数

范围类型描述
火库火库对根Firestore实例的引用。
小路细绳以斜杠分隔的文档路径。
路径细绳[]相对于第一个参数将应用的其他路径段。

返回:

DocumentReference < DocumentDataDocumentData >

DocumentReference实例。

例外情况

如果最终路径具有奇数段,并且没有指向文档。

启用IndexedDbpersistence(firestore,persistencesettings)

此功能将在以后的主要版本中删除。相反,将FirestoreSettings.localCache设置为PersistentLocalCache的实例,以打开索引eddb缓存。当已经指定了FirestoreSettings.localCache时调用此功能会引发异常。

如果可能的话,尝试启用持久存储。

失败时, enableIndexedDbPersistence()将拒绝承诺或抛出例外。这可能会失败的原因有几个,可以在错误上通过code识别。

*失败至上:该应用程序已经在另一个浏览器选项卡中打开。 *未完成:浏览器与离线持久性实现不相容。

请注意,即使发生故障, Firestore实例仍将保持可用,但是离线持久性将被禁用。

持久性不能用于node.js环境中。

签名:

export declare function enableIndexedDbPersistence(firestore: Firestore, persistenceSettings?: PersistenceSettings): Promise<void>;

参数

范围类型描述
火库火库firestore实例可以实现持久性。
持久性持久性可选设置对象要配置持久性。

返回:

承诺<无效>

代表成功实现持久存储的Promise

EnablemultitabIndexedDbpersistence(Firestore)

此功能将在以后的主要版本中删除。相反,将FirestoreSettings.localCache设置为PersistentLocalCache的实例,以打开索引eddb缓存。当已经指定了FirestoreSettings.localCache时调用此功能会引发异常。

如果可能的话,尝试启用多标签持久存储。如果在所有选项卡中启用了所有操作,则所有操作共享对本地持久性的访问,包括查询的共享执行以及在所有连接实例上均具有延迟补偿的本地文档更新。

失败时, enableMultiTabIndexedDbPersistence()将拒绝承诺或抛出例外。这可能会失败的原因有几个,可以在错误上通过code识别。

*失败至上:该应用程序已经在另一个浏览器选项卡中打开,并且未启用多选数。 *未完成:浏览器与离线持久性实现不相容。

请注意,即使发生故障, Firestore实例仍将保持可用,但是离线持久性将被禁用。

签名:

export declare function enableMultiTabIndexedDbPersistence(firestore: Firestore): Promise<void>;

参数

范围类型描述
火库火库firestore实例可以实现持久性。

返回:

承诺<无效>

代表成功实现持久存储的Promise

enablenetwork(firestore)

先前呼叫disablenetwork ()之前,将网络重新使用网络使用该网络。

签名:

export declare function enableNetwork(firestore: Firestore): Promise<void>;

参数

范围类型描述
火库火库

返回:

承诺<无效>

一旦启用网络,就可以解决的Promise

GetPersistentCacheIndexManager(Firestore)

返回给定的Firestore对象使用的PersistentCache索引管理器。

如果未使用本地持久存储,则PersistentCacheIndexManager实例或null

签名:

export declare function getPersistentCacheIndexManager(firestore: Firestore): PersistentCacheIndexManager | null;

参数

范围类型描述
火库火库

返回:

PersistentCacheIndexManager |无效的

LoadBundle(Firestore,Bundledata)

将firestore捆绑包装到本地缓存中。

签名:

export declare function loadBundle(firestore: Firestore, bundleData: ReadableStream<Uint8Array> | ArrayBuffer | string): LoadBundleTask;

参数

范围类型描述
火库火库firestore实例加载捆绑包。
捆绑readableSream <Uint8Array> |数组缓冲区 |细绳代表要加载的捆绑包的对象。有效的对象是ArrayBufferReadableStream<Uint8Array>string

返回:

LoadBundLeTask

LoadBundleTask对象,该对象通知呼叫者进行进度更新以及完成或错误事件。它可以用作Promise<LoadBundleTaskProgress>

名为Query(Firestore,名称)

从给定名称识别的本地缓存中读取Firestore查询

命名的查询被包装成服务器端(以及结果文档)的捆绑包,并使用loadBundle加载到本地缓存。进入本地缓存后,使用此方法按名称提取查询

签名:

export declare function namedQuery(firestore: Firestore, name: string): Promise<Query | null>;

参数

范围类型描述
火库火库firestore实例以读取查询。
姓名细绳查询的名称。

返回:

承诺<查询|空>

通过查询或null解决的Promise

Onsnapshotsync(Firestore,Observer)

为快照中的侦听器附加了一个同步事件。快照中的Sync事件表明,即使单个服务器生成的更改都会影响多个侦听器,也启动了所有受给定更改影响的听众。

注意:快照中的同步事件仅表示听众彼此同步,但与这些快照是否与服务器同步无关。在单个侦听器中使用快照示数,以确定快照是来自缓存还是服务器的快照。

签名:

export declare function onSnapshotsInSync(firestore: Firestore, observer: {
    next?: (value: void) => void;
    error?: (error: FirestoreError) => void;
    complete?: () => void;
}): Unsubscribe;

参数

范围类型描述
火库火库用于同步快照的Firestore实例。
观察者{next?:(value:void)=> void;错误?:(错误: firestoreError )=> void;完整?:()=> void; }一个包含next对象和error回调。

返回:

退订

可以调用的退订函数,以取消快照侦听器。

Onsnapshotsync(Firestore,Onsync)

为快照中的侦听器附加了一个同步事件。快照中的Sync事件表明,即使单个服务器生成的更改都会影响多个侦听器,也启动了所有受给定更改影响的听众。

注意:快照中的同步事件仅表示听众彼此同步,但与这些快照是否与服务器同步无关。在单个侦听器中使用SnapshotMetadata ,以确定快照是来自缓存还是服务器的快照。

签名:

export declare function onSnapshotsInSync(firestore: Firestore, onSync: () => void): Unsubscribe;

参数

范围类型描述
火库火库用于同步快照的Firestore实例。
Onsync () => 无效每当所有快照听众彼此同步时,都会被调用。

返回:

退订

可以调用的退订函数,以取消快照侦听器。

runtransaction(firestore,更新功能,选项)

执行给定的updateFunction ,然后尝试提交交易中应用的更改。如果交易中的任何文档都updateFunction。如果在5次尝试后未能提交,则交易失败。

单个交易中允许的最大写入数为500。

签名:

export declare function runTransaction<T>(firestore: Firestore, updateFunction: (transaction: Transaction) => Promise<T>, options?: TransactionOptions): Promise<T>;

参数

范围类型描述
火库火库对Firestore数据库进行此交易的引用。
更新功能(交易:交易)=>承诺<t>在事务上下文中执行的功能。
选项交易一个选项对象,以配置最大尝试提交的尝试数。

返回:

承诺<T>

如果交易成功完成或明确中止了( updateFunction返回了失败的承诺),则updateFunction退还的承诺在这里返回。否则,如果交易失败,则返回带有相应失败错误的拒绝承诺。

SetIndexConfiguration(Firestore,配置)

此API是作为开发人员的预览提供的,可能会根据我们收到的反馈而更改。不要在生产环境中使用此API。

而不是手动创建缓存索引,而是考虑使用enablePersistentCacheIndexAutoCreation()让SDK决定是否为本地运行的查询创建缓存索引。

为本地查询执行配置索引。任何以前的索引配置都被覆盖。索引配置持续存在后, Promise解决。

索引条目本身是异步创建的。即使尚未可用,您也可以继续使用需要索引的查询。一旦编写了索引条目,查询执行将自动开始使用索引。

索引仅由索引持续性支持。如果未启用indexedDB,则忽略了任何索引配置。

签名:

export declare function setIndexConfiguration(firestore: Firestore, configuration: IndexConfiguration): Promise<void>;

参数

范围类型描述
火库火库firestore实例要配置索引。
配置索引配置索引定义。

返回:

承诺<无效>

一旦成功配置了所有索引,就Promise解决。

例外情况

如果JSON格式无效,则FirestoreError。

SetIndexConfiguration(Firestore,JSON)

此API是作为开发人员的预览提供的,可能会根据我们收到的反馈而更改。不要在生产环境中使用此API。

而不是手动创建缓存索引,而是考虑使用enablePersistentCacheIndexAutoCreation()让SDK决定是否为本地运行的查询创建缓存索引。

为本地查询执行配置索引。任何以前的索引配置都被覆盖。索引配置持续存在后, Promise解决。

索引条目本身是异步创建的。即使尚未可用,您也可以继续使用需要索引的查询。一旦编写了索引条目,查询执行将自动开始使用索引。

索引仅由索引持续性支持。在设置索引配置之前,请启用enableIndexedDbPersistence()enableMultiTabIndexedDbPersistence() 。如果未启用indexedDB,则忽略了任何索引配置。

该方法接受Firebase CLI导出的JSON格式( firebase firestore:indexes )。如果JSON格式无效,则此方法会引发错误。

签名:

export declare function setIndexConfiguration(firestore: Firestore, json: string): Promise<void>;

参数

范围类型描述
火库火库firestore实例要配置索引。
json细绳JSON格式由Firebase CLI导出。

返回:

承诺<无效>

一旦成功配置了所有索引,就Promise解决。

例外情况

如果JSON格式无效,则FirestoreError。

终止(Firestore)

终止提供的Firestore实例。

调用terminate()之后,只能使用clearIndexedDbPersistence()函数。任何其他功能都会抛出FirestoreError

要在终止后重新启动,请使用getfirestore()创建FirebaseFirestore的新实例

终止不会取消任何待处理的写作,并且无法解决等待服务器响应的任何承诺。如果您启用了持久性,下次启动此实例时,它将恢复将这些写入发送给服务器。

签名:

export declare function terminate(firestore: Firestore): Promise<void>;

参数

范围类型描述
火库火库

返回:

承诺<无效>

实例成功终止时解决的Promise将得到解决。

WaitforpendingWrites(Firestore)

等待直到当前正在为活跃用户写作的所有尚待写作已被后端承认。

如果没有出色的写作,返回的承诺立即解决。否则,承诺等待所有先前发行的写入(包括上一个应用程序中写的写信),但它不等待在调用函数后添加的写入。如果您想等待其他写入,请再次致电waitForPendingWrites()

在用户更改期间,任何出色的waitForPendingWrites()承诺将被拒绝。

签名:

export declare function waitForPendingWrites(firestore: Firestore): Promise<void>;

参数

范围类型描述
火库火库

返回:

承诺<无效>

当前所有待处理的写作都被后端所承认时,决心的Promise

写入批次(Firestore)

创建一个写入批次,用于执行多个原子操作。单个写入中允许的最大写入数为500。

与交易不同,写入批次持续脱机,因此,当您不需要在读取数据上进行写入时,最好是可取的。

签名:

export declare function writeBatch(firestore: Firestore): WriteBatch;

参数

范围类型描述
火库火库

返回:

写批处理

可以用来原子执行多个写入的写入批次

功能()

数数()

创建一个聚集的对象,该对象可用于在查询的结果集中计算文档计数。

签名:

export declare function count(): AggregateField<number>;

返回:

聚合字段<数字>

deletefield()

返回sentinel,供{merge: true}updatedoc()setDoc()一起使用,以标记删除字段。

签名:

export declare function deleteField(): FieldValue;

返回:

字段值

DocumentID()

返回一个特殊的哨兵FieldPath ,以参考文档的ID。它可以在查询中用于通过文档ID进行排序或过滤。

签名:

export declare function documentId(): FieldPath;

返回:

野外路径

getfirestore()

返回与默认firbaseApp关联的现有默认firestore实例。如果不存在实例,请用默认设置初始化一个新实例。

签名:

export declare function getFirestore(): Firestore;

返回:

火库

默认应用程序的默认firestore实例。

MemoryEagergarbageCollector()

创建一个MemoryEagerGarbageCollector的实例。除非另有明确指定,否则这也是默认垃圾收集器。

签名:

export declare function memoryEagerGarbageCollector(): MemoryEagerGarbageCollector;

返回:

MemoryEagergarbageCollector

persistentmultipletabmanager()

创建一个PersistentMultipleTabManager的实例

签名:

export declare function persistentMultipleTabManager(): PersistentMultipleTabManager;

返回:

PersistentMultipletabManager

Servertimestamp()

返回与setDoc()updatedoc()一起使用的哨兵,以在书面数据中包括服务器生成的时间戳。

签名:

export declare function serverTimestamp(): FieldValue;

返回:

字段值

函数(数据库,...)

getfirestore(数据库)

此API是作为开发人员的预览提供的,可能会根据我们收到的反馈而更改。不要在生产环境中使用此API。

返回与默认firebaseApp关联的现有命名的firestore实例。如果不存在实例,请用默认设置初始化一个新实例。

签名:

export declare function getFirestore(databaseId: string): Firestore;

参数

范围类型描述
数据库细绳数据库的名称。

返回:

火库

默认应用程序的命名firestore实例。

功能(元素,...)

arrayremove(元素)

返回可以与setDoc()一起使用的特殊值,或告诉服务器从服务器上已经存在的任何数组值中删除给定元素。指定的每个元素的所有实例将从数组中删除。如果要修改的字段还不是一个数组,它将被一个空数组覆盖。

签名:

export declare function arrayRemove(...elements: unknown[]): FieldValue;

参数

范围类型描述
元素未知[]从数组中删除的元素。

返回:

字段值

用于呼叫setDoc()updateDoc()FieldValue Sentinel

阵列(元素)

返回可以与setDoc()updatedoc()一起使用的特殊值,该值告诉服务器将给定元素与服务器上已经存在的任何数组值结合。数组中尚未存在的每个指定元素将添加到末尾。如果要修改的字段还不是数组,它将被包含指定元素的数组覆盖。

签名:

export declare function arrayUnion(...elements: unknown[]): FieldValue;

参数

范围类型描述
元素未知[]将元素变成阵列的要素。

返回:

字段值

用于呼叫setDoc()updateDoc()FieldValue Sentinel

功能(字段,...)

平均(场)

创建一个聚集的对象,该对象可用于在查询结果集中在一系列文档上计算指定字段的平均值。

签名:

export declare function average(field: string | FieldPath): AggregateField<number | null>;

参数

范围类型描述
场地字符串|野外路径在结果集中指定平均的字段。

返回:

聚合字段<号码|空>

总和(字段)

Create an AggregateField object that can be used to compute the sum of a specified field over a range of documents in the result set of a query.

签名:

export declare function sum(field: string | FieldPath): AggregateField<number>;

参数

范围类型描述
场地字符串| FieldPath Specifies the field to sum across the result set.

返回:

聚合字段<数字>

function(fieldPath, ...)

orderBy(fieldPath, directionStr)

Creates a QueryOrderByConstraint that sorts the query result by the specified field, optionally in descending order instead of ascending.

签名:

export declare function orderBy(fieldPath: string | FieldPath, directionStr?: OrderByDirection): QueryOrderByConstraint;

参数

范围类型描述
字段路径字符串| FieldPath The field to sort by.
directionStr OrderByDirection Optional direction to sort by ('asc' or 'desc'). If not specified, order will be ascending.

返回:

QueryOrderByConstraint

The created QueryOrderByConstraint

where(fieldPath, opStr, value)

Creates a QueryFieldFilterConstraint that enforces that documents must contain the specified field and that the value should satisfy the relation constraint provided.

签名:

export declare function where(fieldPath: string | FieldPath, opStr: WhereFilterOp, value: unknown): QueryFieldFilterConstraint;

参数

范围类型描述
字段路径字符串| FieldPath The path to compare
opStr WhereFilterOp The operation string (eg "&lt;", "&lt;=", "==", "&lt;", "&lt;=", "!=").
价值未知The value for comparison

返回:

QueryFieldFilterConstraint

The created QueryFieldFilterConstraint

function(fieldValues, ...)

endAt(fieldValues)

Creates a QueryEndAtConstraint that modifies the result set to end at the provided fields relative to the order of the query. The order of the field values must match the order of the order by clauses of the query.

签名:

export declare function endAt(...fieldValues: unknown[]): QueryEndAtConstraint;

参数

范围类型描述
字段值未知[] The field values to end this query at, in order of the query's order by.

返回:

QueryEndAtConstraint

A QueryEndAtConstraint to pass to query()

endBefore(fieldValues)

Creates a QueryEndAtConstraint that modifies the result set to end before the provided fields relative to the order of the query. The order of the field values must match the order of the order by clauses of the query.

签名:

export declare function endBefore(...fieldValues: unknown[]): QueryEndAtConstraint;

参数

范围类型描述
字段值未知[] The field values to end this query before, in order of the query's order by.

返回:

QueryEndAtConstraint

A QueryEndAtConstraint to pass to query()

startAfter(fieldValues)

Creates a QueryStartAtConstraint that modifies the result set to start after the provided fields relative to the order of the query. The order of the field values must match the order of the order by clauses of the query.

签名:

export declare function startAfter(...fieldValues: unknown[]): QueryStartAtConstraint;

参数

范围类型描述
字段值未知[] The field values to start this query after, in order of the query's order by.

返回:

QueryStartAtConstraint

A QueryStartAtConstraint to pass to query()

startAt(fieldValues)

Creates a QueryStartAtConstraint that modifies the result set to start at the provided fields relative to the order of the query. The order of the field values must match the order of the order by clauses of the query.

签名:

export declare function startAt(...fieldValues: unknown[]): QueryStartAtConstraint;

参数

范围类型描述
字段值未知[] The field values to start this query at, in order of the query's order by.

返回:

QueryStartAtConstraint

A QueryStartAtConstraint to pass to query()

function(indexManager, ...)

deleteAllPersistentCacheIndexes(indexManager)

Removes all persistent cache indexes.

Please note this function will also deletes indexes generated by setIndexConfiguration() , which is deprecated.

签名:

export declare function deleteAllPersistentCacheIndexes(indexManager: PersistentCacheIndexManager): void;

参数

范围类型描述
indexManager PersistentCacheIndexManager

返回:

空白

disablePersistentCacheIndexAutoCreation(indexManager)

Stops creating persistent cache indexes automatically for local query execution. The indexes which have been created by calling enablePersistentCacheIndexAutoCreation() still take effect.

签名:

export declare function disablePersistentCacheIndexAutoCreation(indexManager: PersistentCacheIndexManager): void;

参数

范围类型描述
indexManager PersistentCacheIndexManager

返回:

空白

enablePersistentCacheIndexAutoCreation(indexManager)

Enables the SDK to create persistent cache indexes automatically for local query execution when the SDK believes cache indexes can help improve performance.

默认情况下禁用此功能。

签名:

export declare function enablePersistentCacheIndexAutoCreation(indexManager: PersistentCacheIndexManager): void;

参数

范围类型描述
indexManager PersistentCacheIndexManager

返回:

空白

function(left, ...)

aggregateFieldEqual(left, right)

Compares two 'AggregateField ` instances for equality.

签名:

export declare function aggregateFieldEqual(left: AggregateField<unknown>, right: AggregateField<unknown>): boolean;

参数

范围类型描述
左边聚合字段<未知> Compare this AggregateField to the right .
正确的聚合字段<未知> Compare this AggregateField to the left .

返回:

布尔值

aggregateQuerySnapshotEqual(left, right)

Compares two AggregateQuerySnapshot instances for equality.

Two AggregateQuerySnapshot instances are considered "equal" if they have underlying queries that compare equal, and the same data.

签名:

export declare function aggregateQuerySnapshotEqual<AggregateSpecType extends AggregateSpec, AppModelType, DbModelType extends DocumentData>(left: AggregateQuerySnapshot<AggregateSpecType, AppModelType, DbModelType>, right: AggregateQuerySnapshot<AggregateSpecType, AppModelType, DbModelType>): boolean;

参数

范围类型描述
左边AggregateQuerySnapshot <AggregateSpecType, AppModelType, DbModelType> The first AggregateQuerySnapshot to compare.
正确的AggregateQuerySnapshot <AggregateSpecType, AppModelType, DbModelType> The second AggregateQuerySnapshot to compare.

返回:

布尔值

true if the objects are "equal", as defined above, or false otherwise.

queryEqual(left, right)

Returns true if the provided queries point to the same collection and apply the same constraints.

签名:

export declare function queryEqual<AppModelType, DbModelType extends DocumentData>(left: Query<AppModelType, DbModelType>, right: Query<AppModelType, DbModelType>): boolean;

参数

范围类型描述
左边询问<AppModelType, DbModelType> A Query to compare.
正确的询问<AppModelType, DbModelType> A Query to compare.

返回:

布尔值

true if the references point to the same location in the same Firestore database.

refEqual(left, right)

Returns true if the provided references are equal.

签名:

export declare function refEqual<AppModelType, DbModelType extends DocumentData>(left: DocumentReference<AppModelType, DbModelType> | CollectionReference<AppModelType, DbModelType>, right: DocumentReference<AppModelType, DbModelType> | CollectionReference<AppModelType, DbModelType>): boolean;

参数

范围类型描述
左边DocumentReference <AppModelType, DbModelType> |收藏参考<AppModelType, DbModelType> A reference to compare.
正确的DocumentReference <AppModelType, DbModelType> |收藏参考<AppModelType, DbModelType> A reference to compare.

返回:

布尔值

true if the references point to the same location in the same Firestore database.

snapshotEqual(left, right)

Returns true if the provided snapshots are equal.

签名:

export declare function snapshotEqual<AppModelType, DbModelType extends DocumentData>(left: DocumentSnapshot<AppModelType, DbModelType> | QuerySnapshot<AppModelType, DbModelType>, right: DocumentSnapshot<AppModelType, DbModelType> | QuerySnapshot<AppModelType, DbModelType>): boolean;

参数

范围类型描述
左边DocumentSnapshot <AppModelType, DbModelType> | QuerySnapshot <AppModelType, DbModelType> A snapshot to compare.
正确的DocumentSnapshot <AppModelType, DbModelType> | QuerySnapshot <AppModelType, DbModelType> A snapshot to compare.

返回:

布尔值

true if the snapshots are equal.

function(limit, ...)

limit(limit)

Creates a QueryLimitConstraint that only returns the first matching documents.

签名:

export declare function limit(limit: number): QueryLimitConstraint;

参数

范围类型描述
限制数字The maximum number of items to return.

返回:

QueryLimitConstraint

The created QueryLimitConstraint

limitToLast(limit)

Creates a QueryLimitConstraint that only returns the last matching documents.

You must specify at least one orderBy clause for limitToLast queries, otherwise an exception will be thrown during execution.

签名:

export declare function limitToLast(limit: number): QueryLimitConstraint;

参数

范围类型描述
限制数字The maximum number of items to return.

返回:

QueryLimitConstraint

The created QueryLimitConstraint

function(logLevel, ...)

setLogLevel(logLevel)

Sets the verbosity of Cloud Firestore logs (debug, error, or silent).

签名:

export declare function setLogLevel(logLevel: LogLevel): void;

参数

范围类型描述
日志级别日志级别The verbosity you set for activity and error logging. Can be any of the following values:
  • debug for the most verbose logging level, primarily for debugging.
  • error to log errors only.
  • silent to turn off logging.

返回:

空白

function(n, ...)

increment(n)

Returns a special value that can be used with setDoc() or updateDoc() that tells the server to increment the field's current value by the given value.

If either the operand or the current field value uses floating point precision, all arithmetic follows IEEE 754 semantics. If both values are integers, values outside of JavaScript's safe number range ( Number.MIN_SAFE_INTEGER to Number.MAX_SAFE_INTEGER ) are also subject to precision loss. Furthermore, once processed by the Firestore backend, all integer operations are capped between -2^63 and 2^63-1.

If the current field value is not of type number , or if the field does not yet exist, the transformation sets the field to the given value.

签名:

export declare function increment(n: number): FieldValue;

参数

范围类型描述
n数字The value to increment by.

返回:

字段值

The FieldValue sentinel for use in a call to setDoc() or updateDoc()

function(query, ...)

getAggregateFromServer(query, aggregateSpec)

Calculates the specified aggregations over the documents in the result set of the given query without actually downloading the documents.

Using this function to perform aggregations is efficient because only the final aggregation values, not the documents' data, are downloaded. This function can perform aggregations of the documents in cases where the result set is prohibitively large to download entirely (thousands of documents).

The result received from the server is presented, unaltered, without considering any local state. That is, documents in the local cache are not taken into consideration, neither are local modifications not yet synchronized with the server. Previously-downloaded results, if any, are not used. Every invocation of this function necessarily involves a round trip to the server.

签名:

export declare function getAggregateFromServer<AggregateSpecType extends AggregateSpec, AppModelType, DbModelType extends DocumentData>(query: Query<AppModelType, DbModelType>, aggregateSpec: AggregateSpecType): Promise<AggregateQuerySnapshot<AggregateSpecType, AppModelType, DbModelType>>;

参数

范围类型描述
询问询问<AppModelType, DbModelType> The query whose result set is aggregated over.
aggregateSpec AggregateSpecType An AggregateSpec object that specifies the aggregates to perform over the result set. The AggregateSpec specifies aliases for each aggregate, which can be used to retrieve the aggregate result.

返回:

Promise< AggregateQuerySnapshot <AggregateSpecType, AppModelType, DbModelType>>

例子

const aggregateSnapshot = await getAggregateFromServer(query, {
  countOfDocs: count(),
  totalHours: sum('hours'),
  averageScore: average('score')
});

const countOfDocs: number = aggregateSnapshot.data().countOfDocs;
const totalHours: number = aggregateSnapshot.data().totalHours;
const averageScore: number | null = aggregateSnapshot.data().averageScore;

getCountFromServer(query)

Calculates the number of documents in the result set of the given query without actually downloading the documents.

Using this function to count the documents is efficient because only the final count, not the documents' data, is downloaded. This function can count the documents in cases where the result set is prohibitively large to download entirely (thousands of documents).

The result received from the server is presented, unaltered, without considering any local state. That is, documents in the local cache are not taken into consideration, neither are local modifications not yet synchronized with the server. Previously-downloaded results, if any, are not used. Every invocation of this function necessarily involves a round trip to the server.

签名:

export declare function getCountFromServer<AppModelType, DbModelType extends DocumentData>(query: Query<AppModelType, DbModelType>): Promise<AggregateQuerySnapshot<{
    count: AggregateField<number>;
}, AppModelType, DbModelType>>;

参数

范围类型描述
询问询问<AppModelType, DbModelType> The query whose result set size is calculated.

返回:

Promise< AggregateQuerySnapshot <{ count: AggregateField <number>; }, AppModelType, DbModelType>>

A Promise that will be resolved with the count; the count can be retrieved from snapshot.data().count , where snapshot is the AggregateQuerySnapshot to which the returned Promise resolves.

getDocs(query)

Executes the query and returns the results as a QuerySnapshot

签名:

export declare function getDocs<AppModelType, DbModelType extends DocumentData>(query: Query<AppModelType, DbModelType>): Promise<QuerySnapshot<AppModelType, DbModelType>>;

参数

范围类型描述
询问询问<AppModelType, DbModelType>

返回:

Promise< QuerySnapshot <AppModelType, DbModelType>>

A Promise that will be resolved with the results of the query.

getDocsFromCache(query)

Executes the query and returns the results as a QuerySnapshot from cache. Returns an empty result set if no documents matching the query are currently cached.

签名:

export declare function getDocsFromCache<AppModelType, DbModelType extends DocumentData>(query: Query<AppModelType, DbModelType>): Promise<QuerySnapshot<AppModelType, DbModelType>>;

参数

范围类型描述
询问询问<AppModelType, DbModelType>

返回:

Promise< QuerySnapshot <AppModelType, DbModelType>>

A Promise that will be resolved with the results of the query.

getDocsFromServer(query)

Executes the query and returns the results as a QuerySnapshot from the server. Returns an error if the network is not available.

签名:

export declare function getDocsFromServer<AppModelType, DbModelType extends DocumentData>(query: Query<AppModelType, DbModelType>): Promise<QuerySnapshot<AppModelType, DbModelType>>;

参数

范围类型描述
询问询问<AppModelType, DbModelType>

返回:

Promise< QuerySnapshot <AppModelType, DbModelType>>

A Promise that will be resolved with the results of the query.

onSnapshot(query, observer)

Attaches a listener for QuerySnapshot events. You may either pass individual onNext and onError callbacks or pass a single observer object with next and error callbacks. The listener can be cancelled by calling the function that is returned when onSnapshot is called.

NOTE: Although an onCompletion callback can be provided, it will never be called because the snapshot stream is never-ending.

签名:

export declare function onSnapshot<AppModelType, DbModelType extends DocumentData>(query: Query<AppModelType, DbModelType>, observer: {
    next?: (snapshot: QuerySnapshot<AppModelType, DbModelType>) => void;
    error?: (error: FirestoreError) => void;
    complete?: () => void;
}): Unsubscribe;

参数

范围类型描述
询问询问<AppModelType, DbModelType> The query to listen to.
观察者{ next?: (snapshot: QuerySnapshot <AppModelType, DbModelType>) => void; error?: (error: FirestoreError ) => void; complete?: () => void; } A single object containing next and error callbacks.

返回:

退订

An unsubscribe function that can be called to cancel the snapshot listener.

onSnapshot(query, options, observer)

Attaches a listener for QuerySnapshot events. You may either pass individual onNext and onError callbacks or pass a single observer object with next and error callbacks. The listener can be cancelled by calling the function that is returned when onSnapshot is called.

NOTE: Although an onCompletion callback can be provided, it will never be called because the snapshot stream is never-ending.

签名:

export declare function onSnapshot<AppModelType, DbModelType extends DocumentData>(query: Query<AppModelType, DbModelType>, options: SnapshotListenOptions, observer: {
    next?: (snapshot: QuerySnapshot<AppModelType, DbModelType>) => void;
    error?: (error: FirestoreError) => void;
    complete?: () => void;
}): Unsubscribe;

参数

范围类型描述
询问询问<AppModelType, DbModelType> The query to listen to.
选项SnapshotListenOptions Options controlling the listen behavior.
观察者{ next?: (snapshot: QuerySnapshot <AppModelType, DbModelType>) => void; error?: (error: FirestoreError ) => void; complete?: () => void; } A single object containing next and error callbacks.

返回:

退订

An unsubscribe function that can be called to cancel the snapshot listener.

onSnapshot(query, onNext, onError, onCompletion)

Attaches a listener for QuerySnapshot events. You may either pass individual onNext and onError callbacks or pass a single observer object with next and error callbacks. The listener can be cancelled by calling the function that is returned when onSnapshot is called.

NOTE: Although an onCompletion callback can be provided, it will never be called because the snapshot stream is never-ending.

签名:

export declare function onSnapshot<AppModelType, DbModelType extends DocumentData>(query: Query<AppModelType, DbModelType>, onNext: (snapshot: QuerySnapshot<AppModelType, DbModelType>) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe;

参数

范围类型描述
询问询问<AppModelType, DbModelType> The query to listen to.
下一个(snapshot: QuerySnapshot <AppModelType, DbModelType>) => void A callback to be called every time a new QuerySnapshot is available.
错误时(error: FirestoreError ) => void A callback to be called if the listen fails or is cancelled. No further callbacks will occur.
在完成的时候() => 无效Can be provided, but will not be called since streams are never ending.

返回:

退订

An unsubscribe function that can be called to cancel the snapshot listener.

onSnapshot(query, options, onNext, onError, onCompletion)

Attaches a listener for QuerySnapshot events. You may either pass individual onNext and onError callbacks or pass a single observer object with next and error callbacks. The listener can be cancelled by calling the function that is returned when onSnapshot is called.

NOTE: Although an onCompletion callback can be provided, it will never be called because the snapshot stream is never-ending.

签名:

export declare function onSnapshot<AppModelType, DbModelType extends DocumentData>(query: Query<AppModelType, DbModelType>, options: SnapshotListenOptions, onNext: (snapshot: QuerySnapshot<AppModelType, DbModelType>) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe;

参数

范围类型描述
询问询问<AppModelType, DbModelType> The query to listen to.
选项SnapshotListenOptions Options controlling the listen behavior.
下一个(snapshot: QuerySnapshot <AppModelType, DbModelType>) => void A callback to be called every time a new QuerySnapshot is available.
错误时(error: FirestoreError ) => void A callback to be called if the listen fails or is cancelled. No further callbacks will occur.
在完成的时候() => 无效Can be provided, but will not be called since streams are never ending.

返回:

退订

An unsubscribe function that can be called to cancel the snapshot listener.

query(query, compositeFilter, queryConstraints)

Creates a new immutable instance of Query that is extended to also include additional query constraints.

签名:

export declare function query<AppModelType, DbModelType extends DocumentData>(query: Query<AppModelType, DbModelType>, compositeFilter: QueryCompositeFilterConstraint, ...queryConstraints: QueryNonFilterConstraint[]): Query<AppModelType, DbModelType>;

参数

范围类型描述
询问询问<AppModelType, DbModelType> The Query instance to use as a base for the new constraints.
compositeFilter QueryCompositeFilterConstraint The QueryCompositeFilterConstraint to apply. Create QueryCompositeFilterConstraint using and() or or()
queryConstraints QueryNonFilterConstraint [] Additional QueryNonFilterConstraint s to apply (eg orderBy()限制() )。

返回:

询问<AppModelType, DbModelType>

例外情况

if any of the provided query constraints cannot be combined with the existing or new constraints.

query(query, queryConstraints)

Creates a new immutable instance of Query that is extended to also include additional query constraints.

签名:

export declare function query<AppModelType, DbModelType extends DocumentData>(query: Query<AppModelType, DbModelType>, ...queryConstraints: QueryConstraint[]): Query<AppModelType, DbModelType>;

参数

范围类型描述
询问询问<AppModelType, DbModelType> The Query instance to use as a base for the new constraints.
queryConstraints QueryConstraint [] The list of QueryConstraint申请。

返回:

询问<AppModelType, DbModelType>

例外情况

if any of the provided query constraints cannot be combined with the existing or new constraints.

function(queryConstraints, ...)

and(queryConstraints)

Creates a new QueryCompositeFilterConstraint that is a conjunction of the given filter constraints. A conjunction filter includes a document if it satisfies all of the given filters.

签名:

export declare function and(...queryConstraints: QueryFilterConstraint[]): QueryCompositeFilterConstraint;

参数

范围类型描述
queryConstraints QueryFilterConstraint []选修的。 The list of QueryFilterConstraint s to perform a conjunction for. These must be created with calls to where()或者() , or and()

返回:

QueryCompositeFilterConstraint

The newly created QueryCompositeFilterConstraint

or(queryConstraints)

Creates a new QueryCompositeFilterConstraint that is a disjunction of the given filter constraints. A disjunction filter includes a document if it satisfies any of the given filters.

签名:

export declare function or(...queryConstraints: QueryFilterConstraint[]): QueryCompositeFilterConstraint;

参数

范围类型描述
queryConstraints QueryFilterConstraint []选修的。 The list of QueryFilterConstraint s to perform a disjunction for. These must be created with calls to where()或者() , or and()

返回:

QueryCompositeFilterConstraint

The newly created QueryCompositeFilterConstraint

function(reference, ...)

addDoc(reference, data)

Add a new document to specified CollectionReference with the given data, assigning it a document ID automatically.

签名:

export declare function addDoc<AppModelType, DbModelType extends DocumentData>(reference: CollectionReference<AppModelType, DbModelType>, data: WithFieldValue<AppModelType>): Promise<DocumentReference<AppModelType, DbModelType>>;

参数

范围类型描述
参考收藏参考<AppModelType, DbModelType> A reference to the collection to add this document to.
数据WithFieldValue <AppModelType> An Object containing the data for the new document.

返回:

Promise< DocumentReference <AppModelType, DbModelType>>

A Promise resolved with a DocumentReference pointing to the newly created document after it has been written to the backend (Note that it won't resolve while you're offline).

collection(reference, path, pathSegments)

Gets a CollectionReference instance that refers to a subcollection of reference at the the specified relative path.

签名:

export declare function collection<AppModelType, DbModelType extends DocumentData>(reference: CollectionReference<AppModelType, DbModelType>, path: string, ...pathSegments: string[]): CollectionReference<DocumentData, DocumentData>;

参数

范围类型描述
参考收藏参考<AppModelType, DbModelType> A reference to a collection.
小路细绳以斜线分隔的集合路径。
pathSegments细绳[] Additional path segments to apply relative to the first argument.

返回:

收藏参考< DocumentData , DocumentData >

CollectionReference实例。

例外情况

If the final path has an even number of segments and does not point to a collection.

collection(reference, path, pathSegments)

Gets a CollectionReference instance that refers to a subcollection of reference at the the specified relative path.

签名:

export declare function collection<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>, path: string, ...pathSegments: string[]): CollectionReference<DocumentData, DocumentData>;

参数

范围类型描述
参考DocumentReference <AppModelType, DbModelType> A reference to a Firestore document.
小路细绳以斜线分隔的集合路径。
pathSegments细绳[] Additional path segments that will be applied relative to the first argument.

返回:

收藏参考< DocumentData , DocumentData >

CollectionReference实例。

例外情况

If the final path has an even number of segments and does not point to a collection.

deleteDoc(reference)

Deletes the document referred to by the specified DocumentReference

签名:

export declare function deleteDoc<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>): Promise<void>;

参数

范围类型描述
参考DocumentReference <AppModelType, DbModelType> A reference to the document to delete.

返回:

承诺<无效>

A Promise resolved once the document has been successfully deleted from the backend (note that it won't resolve while you're offline).

doc(reference, path, pathSegments)

Gets a DocumentReference instance that refers to a document within reference at the specified relative path. If no path is specified, an automatically-generated unique ID will be used for the returned DocumentReference

签名:

export declare function doc<AppModelType, DbModelType extends DocumentData>(reference: CollectionReference<AppModelType, DbModelType>, path?: string, ...pathSegments: string[]): DocumentReference<AppModelType, DbModelType>;

参数

范围类型描述
参考收藏参考<AppModelType, DbModelType> A reference to a collection.
小路细绳以斜杠分隔的文档路径。 Has to be omitted to use auto-genrated IDs.
pathSegments细绳[] Additional path segments that will be applied relative to the first argument.

返回:

DocumentReference <AppModelType, DbModelType>

DocumentReference实例。

例外情况

If the final path has an odd number of segments and does not point to a document.

doc(reference, path, pathSegments)

Gets a DocumentReference instance that refers to a document within reference at the specified relative path.

签名:

export declare function doc<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>, path: string, ...pathSegments: string[]): DocumentReference<DocumentData, DocumentData>;

参数

范围类型描述
参考DocumentReference <AppModelType, DbModelType> A reference to a Firestore document.
小路细绳以斜杠分隔的文档路径。
pathSegments细绳[] Additional path segments that will be applied relative to the first argument.

返回:

DocumentReference < DocumentData , DocumentData >

DocumentReference实例。

例外情况

If the final path has an odd number of segments and does not point to a document.

getDoc(reference)

Reads the document referred to by this DocumentReference

签名:

export declare function getDoc<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>): Promise<DocumentSnapshot<AppModelType, DbModelType>>;

参数

范围类型描述
参考DocumentReference <AppModelType, DbModelType> The reference of the document to fetch.

返回:

Promise< DocumentSnapshot <AppModelType, DbModelType>>

A Promise resolved with a DocumentSnapshot containing the current document contents.

getDocFromCache(reference)

Reads the document referred to by this DocumentReference from cache. Returns an error if the document is not currently cached.

签名:

export declare function getDocFromCache<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>): Promise<DocumentSnapshot<AppModelType, DbModelType>>;

参数

范围类型描述
参考DocumentReference <AppModelType, DbModelType>

返回:

Promise< DocumentSnapshot <AppModelType, DbModelType>>

A Promise resolved with a DocumentSnapshot containing the current document contents.

getDocFromServer(reference)

Reads the document referred to by this DocumentReference from the server. Returns an error if the network is not available.

签名:

export declare function getDocFromServer<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>): Promise<DocumentSnapshot<AppModelType, DbModelType>>;

参数

范围类型描述
参考DocumentReference <AppModelType, DbModelType>

返回:

Promise< DocumentSnapshot <AppModelType, DbModelType>>

A Promise resolved with a DocumentSnapshot containing the current document contents.

onSnapshot(reference, observer)

Attaches a listener for DocumentSnapshot events. You may either pass individual onNext and onError callbacks or pass a single observer object with next and error callbacks.

NOTE: Although an onCompletion callback can be provided, it will never be called because the snapshot stream is never-ending.

签名:

export declare function onSnapshot<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>, observer: {
    next?: (snapshot: DocumentSnapshot<AppModelType, DbModelType>) => void;
    error?: (error: FirestoreError) => void;
    complete?: () => void;
}): Unsubscribe;

参数

范围类型描述
参考DocumentReference <AppModelType, DbModelType> A reference to the document to listen to.
观察者{ next?: (snapshot: DocumentSnapshot <AppModelType, DbModelType>) => void; error?: (error: FirestoreError ) => void; complete?: () => void; } A single object containing next and error callbacks.

返回:

退订

An unsubscribe function that can be called to cancel the snapshot listener.

onSnapshot(reference, options, observer)

Attaches a listener for DocumentSnapshot events. You may either pass individual onNext and onError callbacks or pass a single observer object with next and error callbacks.

NOTE: Although an onCompletion callback can be provided, it will never be called because the snapshot stream is never-ending.

签名:

export declare function onSnapshot<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>, options: SnapshotListenOptions, observer: {
    next?: (snapshot: DocumentSnapshot<AppModelType, DbModelType>) => void;
    error?: (error: FirestoreError) => void;
    complete?: () => void;
}): Unsubscribe;

参数

范围类型描述
参考DocumentReference <AppModelType, DbModelType> A reference to the document to listen to.
选项SnapshotListenOptions Options controlling the listen behavior.
观察者{ next?: (snapshot: DocumentSnapshot <AppModelType, DbModelType>) => void; error?: (error: FirestoreError ) => void; complete?: () => void; } A single object containing next and error callbacks.

返回:

退订

An unsubscribe function that can be called to cancel the snapshot listener.

onSnapshot(reference, onNext, onError, onCompletion)

Attaches a listener for DocumentSnapshot events. You may either pass individual onNext and onError callbacks or pass a single observer object with next and error callbacks.

NOTE: Although an onCompletion callback can be provided, it will never be called because the snapshot stream is never-ending.

签名:

export declare function onSnapshot<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>, onNext: (snapshot: DocumentSnapshot<AppModelType, DbModelType>) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe;

参数

范围类型描述
参考DocumentReference <AppModelType, DbModelType> A reference to the document to listen to.
下一个(snapshot: DocumentSnapshot <AppModelType, DbModelType>) => void A callback to be called every time a new DocumentSnapshot is available.
错误时(error: FirestoreError ) => void A callback to be called if the listen fails or is cancelled. No further callbacks will occur.
在完成的时候() => 无效Can be provided, but will not be called since streams are never ending.

返回:

退订

An unsubscribe function that can be called to cancel the snapshot listener.

onSnapshot(reference, options, onNext, onError, onCompletion)

Attaches a listener for DocumentSnapshot events. You may either pass individual onNext and onError callbacks or pass a single observer object with next and error callbacks.

NOTE: Although an onCompletion callback can be provided, it will never be called because the snapshot stream is never-ending.

签名:

export declare function onSnapshot<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>, options: SnapshotListenOptions, onNext: (snapshot: DocumentSnapshot<AppModelType, DbModelType>) => void, onError?: (error: FirestoreError) => void, onCompletion?: () => void): Unsubscribe;

参数

范围类型描述
参考DocumentReference <AppModelType, DbModelType> A reference to the document to listen to.
选项SnapshotListenOptions Options controlling the listen behavior.
下一个(snapshot: DocumentSnapshot <AppModelType, DbModelType>) => void A callback to be called every time a new DocumentSnapshot is available.
错误时(error: FirestoreError ) => void A callback to be called if the listen fails or is cancelled. No further callbacks will occur.
在完成的时候() => 无效Can be provided, but will not be called since streams are never ending.

返回:

退订

An unsubscribe function that can be called to cancel the snapshot listener.

setDoc(reference, data)

Writes to the document referred to by this DocumentReference 。 If the document does not yet exist, it will be created.

签名:

export declare function setDoc<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>, data: WithFieldValue<AppModelType>): Promise<void>;

参数

范围类型描述
参考DocumentReference <AppModelType, DbModelType> A reference to the document to write.
数据WithFieldValue <AppModelType> A map of the fields and values for the document.

返回:

承诺<无效>

A Promise resolved once the data has been successfully written to the backend (note that it won't resolve while you're offline).

setDoc(reference, data, options)

Writes to the document referred to by the specified DocumentReference 。 If the document does not yet exist, it will be created. If you provide merge or mergeFields , the provided data can be merged into an existing document.

签名:

export declare function setDoc<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>, data: PartialWithFieldValue<AppModelType>, options: SetOptions): Promise<void>;

参数

范围类型描述
参考DocumentReference <AppModelType, DbModelType> A reference to the document to write.
数据PartialWithFieldValue <AppModelType> A map of the fields and values for the document.
选项设置选项An object to configure the set behavior.

返回:

承诺<无效>

A Promise resolved once the data has been successfully written to the backend (note that it won't resolve while you're offline).

updateDoc(reference, data)

Updates fields in the document referred to by the specified DocumentReference 。 The update will fail if applied to a document that does not exist.

签名:

export declare function updateDoc<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>, data: UpdateData<DbModelType>): Promise<void>;

参数

范围类型描述
参考DocumentReference <AppModelType, DbModelType> A reference to the document to update.
数据UpdateData <DbModelType> An object containing the fields and values with which to update the document. Fields can contain dots to reference nested fields within the document.

返回:

承诺<无效>

A Promise resolved once the data has been successfully written to the backend (note that it won't resolve while you're offline).

updateDoc(reference, field, value, moreFieldsAndValues)

Updates fields in the document referred to by the specified DocumentReference The update will fail if applied to a document that does not exist.

Nested fields can be updated by providing dot-separated field path strings or by providing FieldPath objects.

签名:

export declare function updateDoc<AppModelType, DbModelType extends DocumentData>(reference: DocumentReference<AppModelType, DbModelType>, field: string | FieldPath, value: unknown, ...moreFieldsAndValues: unknown[]): Promise<void>;

参数

范围类型描述
参考DocumentReference <AppModelType, DbModelType> A reference to the document to update.
场地字符串| FieldPath The first field to update.
价值未知The first value.
moreFieldsAndValues未知[] Additional key value pairs.

返回:

承诺<无效>

A Promise resolved once the data has been successfully written to the backend (note that it won't resolve while you're offline).

function(settings, ...)

memoryLocalCache(settings)

Creates an instance of MemoryLocalCache 。 The instance can be set to FirestoreSettings.cache to tell the SDK which cache layer to use.

签名:

export declare function memoryLocalCache(settings?: MemoryCacheSettings): MemoryLocalCache;

参数

范围类型描述
设置MemoryCacheSettings

返回:

MemoryLocalCache

memoryLruGarbageCollector(settings)

Creates an instance of MemoryLruGarbageCollector

A target size can be specified as part of the setting parameter. The collector will start deleting documents once the cache size exceeds the given size. The default cache size is 40MB (40 * 1024 * 1024 bytes).

签名:

export declare function memoryLruGarbageCollector(settings?: {
    cacheSizeBytes?: number;
}): MemoryLruGarbageCollector;

参数

范围类型描述
设置{ cacheSizeBytes?: number; }

返回:

MemoryLruGarbageCollector

persistentLocalCache(settings)

Creates an instance of PersistentLocalCache 。 The instance can be set to FirestoreSettings.cache to tell the SDK which cache layer to use.

Persistent cache cannot be used in a Node.js environment.

签名:

export declare function persistentLocalCache(settings?: PersistentCacheSettings): PersistentLocalCache;

参数

范围类型描述
设置PersistentCacheSettings

返回:

PersistentLocalCache

persistentSingleTabManager(settings)

Creates an instance of PersistentSingleTabManager

签名:

export declare function persistentSingleTabManager(settings: PersistentSingleTabManagerSettings | undefined): PersistentSingleTabManager;

参数

范围类型描述
设置PersistentSingleTabManagerSettings |不明确的Configures the created tab manager.

返回:

PersistentSingleTabManager

function(snapshot, ...)

endAt(snapshot)

Creates a QueryEndAtConstraint that modifies the result set to end at the provided document (inclusive). The end position is relative to the order of the query. The document must contain all of the fields provided in the orderBy of the query.

签名:

export declare function endAt<AppModelType, DbModelType extends DocumentData>(snapshot: DocumentSnapshot<AppModelType, DbModelType>): QueryEndAtConstraint;

参数

范围类型描述
快照DocumentSnapshot <AppModelType, DbModelType> The snapshot of the document to end at.

返回:

QueryEndAtConstraint

A QueryEndAtConstraint to pass to query()

endBefore(snapshot)

Creates a QueryEndAtConstraint that modifies the result set to end before the provided document (exclusive). The end position is relative to the order of the query. The document must contain all of the fields provided in the orderBy of the query.

签名:

export declare function endBefore<AppModelType, DbModelType extends DocumentData>(snapshot: DocumentSnapshot<AppModelType, DbModelType>): QueryEndAtConstraint;

参数

范围类型描述
快照DocumentSnapshot <AppModelType, DbModelType> The snapshot of the document to end before.

返回:

QueryEndAtConstraint

A QueryEndAtConstraint to pass to query()

startAfter(snapshot)

Creates a QueryStartAtConstraint that modifies the result set to start after the provided document (exclusive). The starting position is relative to the order of the query. The document must contain all of the fields provided in the orderBy of the query.

签名:

export declare function startAfter<AppModelType, DbModelType extends DocumentData>(snapshot: DocumentSnapshot<AppModelType, DbModelType>): QueryStartAtConstraint;

参数

范围类型描述
快照DocumentSnapshot <AppModelType, DbModelType> The snapshot of the document to start after.

返回:

QueryStartAtConstraint

A QueryStartAtConstraint to pass to query()

startAt(snapshot)

Creates a QueryStartAtConstraint that modifies the result set to start at the provided document (inclusive). The starting position is relative to the order of the query. The document must contain all of the fields provided in the orderBy of this query.

签名:

export declare function startAt<AppModelType, DbModelType extends DocumentData>(snapshot: DocumentSnapshot<AppModelType, DbModelType>): QueryStartAtConstraint;

参数

范围类型描述
快照DocumentSnapshot <AppModelType, DbModelType> The snapshot of the document to start at.

返回:

QueryStartAtConstraint

A QueryStartAtConstraint to pass to query()

CACHE_SIZE_UNLIMITED

Constant used to indicate the LRU garbage collection should be disabled. Set this value as the cacheSizeBytes on the settings passed to the Firestore instance.

签名:

CACHE_SIZE_UNLIMITED = -1

AddPrefixToKeys

Returns a new map where every key is prefixed with the outer key appended to a dot.

签名:

export declare type AddPrefixToKeys<Prefix extends string, T extends Record<string, unknown>> = {
    [K in keyof T & string as `${Prefix}.${K}`]+?: string extends K ? any : T[K];
};

AggregateFieldType

The union of all AggregateField types that are supported by Firestore.

签名:

export declare type AggregateFieldType = ReturnType<typeof sum> | ReturnType<typeof average> | ReturnType<typeof count>;

AggregateSpecData

A type whose keys are taken from an AggregateSpec , and whose values are the result of the aggregation performed by the corresponding AggregateField from the input AggregateSpec

签名:

export declare type AggregateSpecData<T extends AggregateSpec> = {
    [P in keyof T]: T[P] extends AggregateField<infer U> ? U : never;
};

聚合类型

Union type representing the aggregate type to be performed.

签名:

export declare type AggregateType = 'count' | 'avg' | 'sum';

ChildUpdateFields

Helper for calculating the nested fields for a given type T1. This is needed to distribute union types such as undefined | {...} (happens for optional props) or {a: A} | {b: B}

In this use case, V is used to distribute the union types of T[K] on Record , since T[K] is evaluated as an expression and not distributed.

See https://www.typescriptlang.org/docs/handbook/advanced-types.html#distributive-conditional-types

签名:

export declare type ChildUpdateFields<K extends string, V> = V extends Record<string, unknown> ? AddPrefixToKeys<K, UpdateData<V>> : never;

DocumentChangeType

The type of a DocumentChange may be 'added', 'removed', or 'modified'.

签名:

export declare type DocumentChangeType = 'added' | 'removed' | 'modified';

FirestoreErrorCode

The set of Firestore status codes. The codes are the same at the ones exposed by gRPC here: https://github.com/grpc/grpc/blob/master/doc/statuscodes.md

Possible values: - 'cancelled': The operation was cancelled (typically by the caller). - 'unknown': Unknown error or an error from a different error domain. - 'invalid-argument': Client specified an invalid argument. Note that this differs from 'failed-precondition'. 'invalid-argument' indicates arguments that are problematic regardless of the state of the system (eg an invalid field name). - 'deadline-exceeded': Deadline expired before operation could complete. For operations that change the state of the system, this error may be returned even if the operation has completed successfully. For example, a successful response from a server could have been delayed long enough for the deadline to expire. - 'not-found': Some requested document was not found. - 'already-exists': Some document that we attempted to create already exists. - 'permission-denied': The caller does not have permission to execute the specified operation. - 'resource-exhausted': Some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out of space. - 'failed-precondition': Operation was rejected because the system is not in a state required for the operation's execution. - 'aborted': The operation was aborted, typically due to a concurrency issue like transaction aborts, etc. - 'out-of-range': Operation was attempted past the valid range. - 'unimplemented': Operation is not implemented or not supported/enabled. - 'internal': Internal errors. Means some invariants expected by underlying system has been broken. If you see one of these errors, something is very broken. - 'unavailable': The service is currently unavailable. This is most likely a transient condition and may be corrected by retrying with a backoff. - 'data-loss': Unrecoverable data loss or corruption. - 'unauthenticated': The request does not have valid authentication credentials for the operation.

签名:

export declare type FirestoreErrorCode = 'cancelled' | 'unknown' | 'invalid-argument' | 'deadline-exceeded' | 'not-found' | 'already-exists' | 'permission-denied' | 'resource-exhausted' | 'failed-precondition' | 'aborted' | 'out-of-range' | 'unimplemented' | 'internal' | 'unavailable' | 'data-loss' | 'unauthenticated';

FirestoreLocalCache

Union type from all supported SDK cache layer.

签名:

export declare type FirestoreLocalCache = MemoryLocalCache | PersistentLocalCache;

ListenSource

Describe the source a query listens to.

Set to default to listen to both cache and server changes. Set to cache to listen to changes in cache only.

签名:

export declare type ListenSource = 'default' | 'cache';

MemoryGarbageCollector

Union type from all support gabage collectors for memory local cache.

签名:

export declare type MemoryGarbageCollector = MemoryEagerGarbageCollector | MemoryLruGarbageCollector;

NestedUpdateFields

For each field (eg 'bar'), find all nested keys (eg { 'bar.baz': T1, 'bar.qux': T2 } )。 Intersect them together to make a single map containing all possible keys that are all marked as optional

签名:

export declare type NestedUpdateFields<T extends Record<string, unknown>> = UnionToIntersection<{
    [K in keyof T & string]: ChildUpdateFields<K, T[K]>;
}[keyof T & string]>;

OrderByDirection

The direction of a orderBy() clause is specified as 'desc' or 'asc' (descending or ascending).

签名:

export declare type OrderByDirection = 'desc' | 'asc';

PartialWithFieldValue

Similar to Typescript's Partial<T> , but allows nested fields to be omitted and FieldValues to be passed in as property values.

签名:

export declare type PartialWithFieldValue<T> = Partial<T> | (T extends Primitive ? T : T extends {} ? {
    [K in keyof T]?: PartialWithFieldValue<T[K]> | FieldValue;
} : never);

PersistentTabManager

A union of all available tab managers.

签名:

export declare type PersistentTabManager = PersistentSingleTabManager | PersistentMultipleTabManager;

原始

Primitive types.

签名:

export declare type Primitive = string | number | boolean | undefined | null;

QueryConstraintType

Describes the different query constraints available in this SDK.

签名:

export declare type QueryConstraintType = 'where' | 'orderBy' | 'limit' | 'limitToLast' | 'startAt' | 'startAfter' | 'endAt' | 'endBefore';

QueryFilterConstraint

QueryFilterConstraint is a helper union type that represents QueryFieldFilterConstraint and QueryCompositeFilterConstraint

签名:

export declare type QueryFilterConstraint = QueryFieldFilterConstraint | QueryCompositeFilterConstraint;

QueryNonFilterConstraint

QueryNonFilterConstraint is a helper union type that represents QueryConstraints which are used to narrow or order the set of documents, but that do not explicitly filter on a document field. QueryNonFilterConstraint s are created by invoking orderBy() , startAt() , startAfter() , endBefore() , endAt() , limit() or limitToLast() and can then be passed to query() to create a new query instance that also contains the QueryConstraint

签名:

export declare type QueryNonFilterConstraint = QueryOrderByConstraint | QueryLimitConstraint | QueryStartAtConstraint | QueryEndAtConstraint;

设置选项

An options object that configures the behavior of setDoc() , and calls. These calls can be configured to perform granular merges instead of overwriting the target documents in their entirety by providing a SetOptions with merge: true

签名:

export declare type SetOptions = {
    readonly merge?: boolean;
} | {
    readonly mergeFields?: Array<string | FieldPath>;
};

TaskState

Represents the state of bundle loading tasks.

Both 'Error' and 'Success' are sinking state: task will abort or complete and there will be no more updates after they are reported.

签名:

export declare type TaskState = 'Error' | 'Running' | 'Success';

UnionToIntersection

Given a union type U = T1 | T2 | ... , returns an intersected type (T1 & T2 & ...)

Uses distributive conditional types and inference from conditional types. This works because multiple candidates for the same type variable in contra-variant positions causes an intersection type to be inferred. https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-inference-in-conditional-types https://stackoverflow.com/questions/50374908/transform-union-type-to-intersection -类型

签名:

export declare type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;

UpdateData

Update data (for use with updateDoc() ) that consists of field paths (eg 'foo' or 'foo.baz') mapped to values. Fields that contain dots reference nested fields within the document. FieldValues can be passed in as property values.

签名:

export declare type UpdateData<T> = T extends Primitive ? T : T extends {} ? {
    [K in keyof T]?: UpdateData<T[K]> | FieldValue;
} & NestedUpdateFields<T> : Partial<T>;

WhereFilterOp

Filter conditions in a where() clause are specified using the strings '&lt;', '&lt;=', '==', '!=', '&gt;=', '&gt;', 'array-contains', 'in', 'array-contains-any', and 'not-in'.

签名:

export declare type WhereFilterOp = '<' | '<=' | '==' | '!=' | '>=' | '>' | 'array-contains' | 'in' | 'array-contains-any' | 'not-in';

WithFieldValue

Allows FieldValues to be passed in as a property value while maintaining type safety.

签名:

export declare type WithFieldValue<T> = T | (T extends Primitive ? T : T extends {} ? {
    [K in keyof T]: WithFieldValue<T[K]> | FieldValue;
} : never);