原生模式下的 Cloud Firestore 企业版现已推出!
了解详情。
字面量
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
说明
从一组固定的预定义文档对象返回文档。
此阶段通常用于单独测试其他阶段,不过也可用作联接条件的输入。
语法
Node.js
const results = await db.pipeline()
.literals({ name: "joe", age: 10 }, { name: "bob", age: 30 }, { name: "alice", age: 40 })
.where(field("age").lessThan(35))
.execute();
...
[
{ name: "joe", age: 10 },
{ name: "bob", age: 30 }
]
行为
literals(...) 阶段只能用作流水线(或子流水线)中的第一个阶段。从 literals 返回的文档的顺序与它们的定义顺序一致。
虽然字面量值是最常见的,但也可以传入表达式,系统将对这些表达式进行计算并返回结果,从而无需先创建一些测试数据即可测试不同的查询/表达式行为。
例如,以下内容展示了如何在一些常量测试集上快速测试 length(...) 函数:
Node.js
const results = await db.pipeline()
.literals({ x: constant("foo-bar-baz").length() }, { x: constant("bar").length() })
.execute();
...
[
{ x: 11 },
{ x: 3 }
]
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2026-03-05。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2026-03-05。"],[],[]]