0

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);
});

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' } ] }

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

JeremyW
  • 5,157
  • 6
  • 29
  • 30
Thirumani
  • 45
  • 1
  • 10
  • I'm having trouble figuring out what your actual document looks like. Can you post a screenshot of the `myTest` document as it shows in the [Firebase Database console](https://console.firebase.google.com/project/_/database/data/)? – Frank van Puffelen Jun 27 '18 at 13:10
  • In what way is it "not working"? Do you get wrong output, or none at all, or an error? – Roland Weber Jun 27 '18 at 13:16

1 Answers1

0

test.data()['tests'] doesn't return an array, it returns a map {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));

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

Kokogino
  • 984
  • 1
  • 5
  • 17