我已经有了答案:
const faunadb = require('faunadb')
const q = faunadb.query
exports.handler = async (event, context) => {
const client = new faunadb.Client({
secret: process.env.FAUNADB_SERVER_SECRET
})
try {
// Getting the refs with a first query
let refs = await client.query(q.Paginate(q.Match(q.Index('skus'))))
// Forging a second query with the retrieved refs
const bigQuery = refs.data.map((ref) => q.Get(ref))
// Sending over that second query
let allDocuments = await client.query(bigQuery)
// All my documents are here!
console.log('@allDocuments: ', allDocuments);
//...
} catch (err) {
// ...
}
}
但我觉得它不令人满意,因为我正在对似乎最微不足道的数据库调用进行 2 次查询。对我来说,这似乎效率低下且冗长。
因为我刚刚了解 FaunaDB,所以这里可能有些东西我没有掌握。我的问题可以分为3个:
- 我可以在一次调用中查询所有文档吗?
- 如果不是,为什么不呢?这样的设计背后的逻辑是什么?
- 我可以在没有索引的情况下进行这样的查询吗?