本文介绍了从Cloud Firestore获得价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码从Cloud Firestore中获取价值

I am getting value from cloud firestore using the code below

dbManager = admin.initializeApp(functions.config().firebase);

this.dbManager.collection("test").doc("myTest").get().then( async test=> {
    console.log("test---------------->",test);
    console.log("test---------------->",test._fieldsProto['tests']);
    console.log("test---data------------->",test.data()['tests'].values);
});

和当我使用 test.data()['tests'] 时获得的值是

and the value I get when I use test.data()['tests'] is

{ values:
   [ { mapValue: [Object], valueType: 'mapValue' },
     { mapValue: [Object], valueType: 'mapValue' },
     { mapValue: [Object], valueType: 'mapValue' },
     { mapValue: [Object], valueType: 'mapValue' },
     { mapValue: [Object], valueType: 'mapValue' },
     { mapValue: [Object], valueType: 'mapValue' },
     { mapValue: [Object], valueType: 'mapValue' },
     { mapValue: [Object], valueType: 'mapValue' },
     { mapValue: [Object], valueType: 'mapValue' } ] }

如何从中获得价值?当我尝试使用像 test.data()['tests'].array.forEach 之类的foreach时,它不起作用.

How do I get values from this? When I try with foreach like test.data()['tests'].array.forEach it is not working.

推荐答案

test.data()['tests'] 不返回数组,而是返回映射 {values:[]} .

test.data()['tests'] doesn't return an array, it returns a map {values: []}.

您需要做的是首先获取 values ,然后在数组上循环:

What you need to do is first get values and then loop over the array:

test.data()['tests'].values.forEach(x => console.log(x));

console.log()替换为您想对所有条目进行的操作.

Replace the console.log() with whatever you wanna do with all the entries.

这篇关于从Cloud Firestore获得价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 13:15