I started my Creating my react native android App using realtime database but later realised that i could'nt carry out some queries(like where) so i changed to cloud firestore but i have found trouble changing code meant for realtime database to cloud firestore. I have this for the real time database which works well
firebase.database().ref('/users').on('value', (snapshot) => {
let data = snapshot.val();
let items = Object.values(data);
this.setState({items});
}).catch(function(error) {
var errorCode = error.code;
var errorMessage = error.message;
this.setState({ errorMessage: errorMessage })
});
I have tried to yield the code above in cloud firestore as shown below but doesn't work(a typeerror pops up and states that snapshot.val is not a function).
firebase.firestore().collection('users').get().then((snapshot)=>{
let data = snapshot.val();
let items = Object.values(data);
this.setState({items});
}).catch(function(error) {
var errorCode = error.code;
var errorMessage = error.message;
this.setState({ errorMessage: errorMessage })
});
This is in my database project
How can i yield working corresponding cloud firestore code?