node.js firestore查询选择字段路径列表



我尝试创建并返回一个新的查询实例,该实例将字段掩码应用于结果,并仅返回指定的字段子集。

我使用:

let query = firestore.collection('col').select('field1','field2','field3').get() ...

没关系,查询仅用3个指定字段返回所有集合文档。

在我的上下文应用程序中,指定的字段列表在配置文档上。当我使用时:

let fieldsList = ['field1','field2','field3'];    
let query = firestore.collection('col').select(fieldsList).get() ...

我有一个错误消息"索引0的参数不是有效的fieldpath ...

在Google文档上,它被指定为" 您可以指定返回的字段路径列表" "

所以,我不知道如何将字段路径列表传递给查询选择方法。

非常感谢您的帮助!

您正在处理所谓的spread syntax。为了使其正常工作,它需要在fieldList的前面添加三点:

let query = firestore.collection('col').select(...fieldsList).get() ..

最新更新