我有一个名为"用户"的集合,它有2个文档"A"和"B".现在我有2个用户,但以后我可能会有更多的用户,所以我必须列出文档.我需要找到一个名为Device Name的字段.我需要找出每个用户的设备名称.
我使用了以下代码,但它只能找到我列出的文档:
DocumentReference documentRef = db.Collection("User").Document("A");
DocumentReference documentRef2 = db.Collection("User").Document("B");
DocumentSnapshot documentSnapshot = await documentRef.GetSnapshotAsync();
DocumentSnapshot documentSnapshot2 = await documentRef2.GetSnapshotAsync();
if (documentSnapshot.Exists && documentSnapshot2.Exists)
{
string deviceName = documentSnapshot.GetValue<string>("Device Name");
string deviceName2 = documentSnapshot2.GetValue<string>("Device Name");
MessageBox.Show($"Device Name: {deviceName}");
MessageBox.Show($"Device Name 2: {deviceName2}");
}
else
{
MessageBox.Show("Document does not exist.");
}