我创建了数据库和一个集合。现在我想从这个集合中检索所有文档。
我使用了这种查询方法:
q.Map(
q.Paginate(Documents(Collection('posts'))),
q.Lambda(x => q.Get(x))
).then (x=>console.log(x))
但是每次我运行这段代码时,它都会向我发送一条错误消息,告诉我 Documents is not defined 。谁能告诉我问题是什么?
我创建了数据库和一个集合。现在我想从这个集合中检索所有文档。
我使用了这种查询方法:
q.Map(
q.Paginate(Documents(Collection('posts'))),
q.Lambda(x => q.Get(x))
).then (x=>console.log(x))
但是每次我运行这段代码时,它都会向我发送一条错误消息,告诉我 Documents is not defined 。谁能告诉我问题是什么?
你用q。在 Map、Paginate 和 Lambda 前面。我认为这意味着您没有执行以下操作
import faunadb from 'faunadb'
const q = faunadb.query
const { Documents, Paginate, Collections, Lambda, Get } = q
如果你这样做了,这应该工作。(免责声明:确保不要覆盖特定语言的函数,如 Map 和 or Function,对于这些,请使用 q.Function 和 q.Map。
另一种方法是将 q 放在所有内容的前面。
q.Map(
q.Paginate(q.Documents(q.Collection('posts'))),
q.Lambda(x => q.Get(x))
).then (x=>console.log(x))
如前所述,如果您确实公开了这些函数(我个人觉得这很方便),请不要使用 Map 这样做,因为这是一个 JavaScript 关键字,所以您能得到的最好的结果是:
import faunadb from 'faunadb'
const q = faunadb.query
const { Documents, Paginate, Collections, Lambda, Get } = q
q.Map(
Paginate(Documents(Collection('posts'))),
Lambda(x => Get(x))
).then (x=>console.log(x))