如何获取 Firebase 集合中的所有文档(包括不存在的祖先文档)? [英] How do you fetch all documents (including non-existent ancestor documents) in a Firebase collection?
问题描述
我正在尝试提取users"集合中的所有文档,但它只提取fred"和lisa",而忽略了所有斜体文档:
I am trying to pull all the documents in the collection 'users', but it only pulls 'fred' and 'lisa', and ignores all the italicized documents:
对于这个数据:
尝试获取所有文档:
将产生:
info: length 2
info: fred => { gender: 'male', contacts: [ '' ] }
lisa => { contacts: [ '' ] }
根据 Firebase 文档(Firebase:添加和管理数据):
According to the Firebase documentation (Firebase: Add and Manage Data):
警告:即使不存在的祖先文档出现在控制台中,它们也不会出现在查询和快照中.您必须创建文档以将其包含在查询结果中.
Warning: Even though non-existent ancestor documents appear in the console, they do not appear in queries and snapshots. You must create the document to include it in query results.
注意:当用户点击触发 firebase.auth()
函数的注册按钮时,不存在的祖先用户似乎是自动创建的(fred
和 lisa
是手动创建的).
Note: The non-existent ancestor users seem to be auto-created when the user hits the sign-up button that triggers a firebase.auth()
function (fred
and lisa
were created manually).
如果某些用户没有出现在我的查询中,我将如何打印每个用户的 contacts
?我是否需要定期运行手动重新添加所有用户的脚本,还是有更优雅的解决方案?
How would I print the contacts
of each user if some of the users do not show up in my queries? Would I need to periodically run a script that manually re-adds all the users or is there a more elegant solution?
推荐答案
如果您尝试从 Firebase 身份验证中列出所有注册用户,您可以使用 Firebase SDK 功能:
If you're trying to list all your registered users from Firebase auth, you can use the Firebase SDK function:
function listAllUsers(nextPageToken) {
admin.auth().listUsers(1000, nextPageToken)
.then(function(listUsersResult){
listUsersResult.users.forEach(function(userRecord) {
console.log('user', userRecord.toJSON());
})
if (listUsersResult.pageToken) {
// list next batch of users
}
})
.catch(function(err) {
console.log('Error listing users: ', error)
});
}
listAllUsers();
通过 http://firebase.google.com/docs/auth/admin/manage-users#list_all_users
这篇关于如何获取 Firebase 集合中的所有文档(包括不存在的祖先文档)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!