参数
collectionstring必填哪个收藏
filterJSON text查询 空或空 意味着一切 都与 limit.
options.limitinteger有多少个? 0 意思是无限制,这很少是你想要的。
options.skipinteger有多少人可以跨过——这个加 limit 正在呼叫。
options.sortobject{ field: 1 | -1 }.
options.projectionobject返回的字段。更少的字段,回答较小。
await storage.run({
action: "find",
collection: "orders",
filter: JSON.stringify({ status: "paid", amount: { $gt: 100 } }),
options: { limit: 20, skip: 0, sort: { createdAt: -1 },
projection: { _id: 1, amount: 1, customer: 1 } },
});
// [{ _id: "…", amount: 240, customer: { … } }]import json
storage.run(
action="find",
collection="orders",
filter=json.dumps({"status": "paid", "amount": {"$gt": 100}}),
options={"limit": 20, "skip": 0, "sort": {"createdAt": -1},
"projection": {"_id": 1, "amount": 1, "customer": 1}},
)
# [{"_id": "…", "amount": 240, "customer": {…}}]将过滤器发送为 JSON 文字文字文字文字
不是作为对象。 嵌套对象在通过一些呼叫器时会丢失以美元开头的键, 查询会比您想要的更匹配, 无需说明。
身份识别符已被转换为您
A 音 A _id 指定字符串后, 将字符串转换为数据库所期望的标识符类型, 包括内部 $in, $nin 和 $ne。这样你就可以把打印的代号传回去, 而不自己转换。
filter: JSON.stringify({ _id: "66f0c1a2b3c4d5e6f7a8b9c0" })
filter: JSON.stringify({ _id: { $in: [idA, idB] } })filter = json.dumps({"_id": "66f0c1a2b3c4d5e6f7a8b9c0"})
filter = json.dumps({"_id": {"$in": [id_a, id_b]}})呼叫
async function* pages(storage, collection, filter, size = 100) {
for (let skip = 0; ; skip += size) {
const rows = await storage.run({ action: "find", collection, filter,
options: { limit: size, skip, sort: { _id: 1 } } });
if (!rows.length) return;
yield rows;
if (rows.length < size) return;
}
}def pages(storage, collection, filter, size=100):
skip = 0
while True:
rows = storage.run(action="find", collection=collection, filter=filter,
options={"limit": size, "skip": skip, "sort": {"_id": 1}})
if not rows:
return
yield rows
if len(rows) < size:
return
skip += size排序在稳定的东西 - _id 安全默认值。未排序查询的调用可两次显示同一文档,但错失另一文档。
被拒绝的
包含过滤器的过滤器 $where, $function 或 $accumulator 被拒绝:他们在数据库内运行代码。拒绝发生在查询发送之前。