I’m inserting data in Firestore DB but it doesn’t show up in the Firestore UI. But when I run the query using the react-native library I get results back. Anyone know why this might be happening?
These are the logs:
<code> LOG Total users: 15
LOG User ID: 00HxI74CXbjk54IaFOiu {"age": 39, "name": "Fernando"}
LOG User ID: 2rBtzjf9W9cCfADx20V6 {"age": 39, "name": "Fernando"}
LOG User ID: 99YNpKHMIcTls9PYKGQ9 {"age": 39, "name": "Fernando"}
LOG User ID: P1XF5ICg6KgcDYyA069j {"age": 39, "name": "Fernando"}
LOG User ID: Pm18VRl9Tl0ES6sDF7oT {"age": 39, "name": "Fernando"}
...
</code>
<code> LOG Total users: 15
LOG User ID: 00HxI74CXbjk54IaFOiu {"age": 39, "name": "Fernando"}
LOG User ID: 2rBtzjf9W9cCfADx20V6 {"age": 39, "name": "Fernando"}
LOG User ID: 99YNpKHMIcTls9PYKGQ9 {"age": 39, "name": "Fernando"}
LOG User ID: P1XF5ICg6KgcDYyA069j {"age": 39, "name": "Fernando"}
LOG User ID: Pm18VRl9Tl0ES6sDF7oT {"age": 39, "name": "Fernando"}
...
</code>
LOG Total users: 15
LOG User ID: 00HxI74CXbjk54IaFOiu {"age": 39, "name": "Fernando"}
LOG User ID: 2rBtzjf9W9cCfADx20V6 {"age": 39, "name": "Fernando"}
LOG User ID: 99YNpKHMIcTls9PYKGQ9 {"age": 39, "name": "Fernando"}
LOG User ID: P1XF5ICg6KgcDYyA069j {"age": 39, "name": "Fernando"}
LOG User ID: Pm18VRl9Tl0ES6sDF7oT {"age": 39, "name": "Fernando"}
...
And this is my code:
<code>import React, { useEffect } from 'react';
import { View, Text, Button } from 'react-native';
import firebase from '@react-native-firebase/app';
import firestore from '@react-native-firebase/firestore';
// Configuración de Firebase
const firebaseConfig = {
apiKey: "",
authDomain: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: "",
measurementId: ""
};
// Inicializar Firebase
if (!firebase.apps.length) {
console.log('Initializing Firebase');
firebase.initializeApp(firebaseConfig);
} else {
console.log('Firebase already initialized');
}
export default function App() {
useEffect(() => {
// console.log('Firestore instance:', firestore());
}, []);
const addUser = async () => {
console.log('adding user');
console.log(firestore().app.name);
const usersRef = firestore().collection('Users');
usersRef.add({
name: 'Fernando',
age: 39,
})
.then(() => {
console.log('User added!');
});
usersRef
// Filter results
.where('age', '==', 39)
.get()
.then(querySnapshot => {
console.log('Total users: ', querySnapshot.size);
querySnapshot.forEach(documentSnapshot => {
console.log('User ID: ', documentSnapshot.id, documentSnapshot.data());
});
});
console.log('done');
};
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Add User to Firestore</Text>
<Button title="Add User" onPress={addUser} />
</View>
);
}
</code>
<code>import React, { useEffect } from 'react';
import { View, Text, Button } from 'react-native';
import firebase from '@react-native-firebase/app';
import firestore from '@react-native-firebase/firestore';
// Configuración de Firebase
const firebaseConfig = {
apiKey: "",
authDomain: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: "",
measurementId: ""
};
// Inicializar Firebase
if (!firebase.apps.length) {
console.log('Initializing Firebase');
firebase.initializeApp(firebaseConfig);
} else {
console.log('Firebase already initialized');
}
export default function App() {
useEffect(() => {
// console.log('Firestore instance:', firestore());
}, []);
const addUser = async () => {
console.log('adding user');
console.log(firestore().app.name);
const usersRef = firestore().collection('Users');
usersRef.add({
name: 'Fernando',
age: 39,
})
.then(() => {
console.log('User added!');
});
usersRef
// Filter results
.where('age', '==', 39)
.get()
.then(querySnapshot => {
console.log('Total users: ', querySnapshot.size);
querySnapshot.forEach(documentSnapshot => {
console.log('User ID: ', documentSnapshot.id, documentSnapshot.data());
});
});
console.log('done');
};
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Add User to Firestore</Text>
<Button title="Add User" onPress={addUser} />
</View>
);
}
</code>
import React, { useEffect } from 'react';
import { View, Text, Button } from 'react-native';
import firebase from '@react-native-firebase/app';
import firestore from '@react-native-firebase/firestore';
// Configuración de Firebase
const firebaseConfig = {
apiKey: "",
authDomain: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: "",
measurementId: ""
};
// Inicializar Firebase
if (!firebase.apps.length) {
console.log('Initializing Firebase');
firebase.initializeApp(firebaseConfig);
} else {
console.log('Firebase already initialized');
}
export default function App() {
useEffect(() => {
// console.log('Firestore instance:', firestore());
}, []);
const addUser = async () => {
console.log('adding user');
console.log(firestore().app.name);
const usersRef = firestore().collection('Users');
usersRef.add({
name: 'Fernando',
age: 39,
})
.then(() => {
console.log('User added!');
});
usersRef
// Filter results
.where('age', '==', 39)
.get()
.then(querySnapshot => {
console.log('Total users: ', querySnapshot.size);
querySnapshot.forEach(documentSnapshot => {
console.log('User ID: ', documentSnapshot.id, documentSnapshot.data());
});
});
console.log('done');
};
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Add User to Firestore</Text>
<Button title="Add User" onPress={addUser} />
</View>
);
}
Also something that I don’t understand is when I log the app name => console.log(firestore().app.name);
I get the following: LOG [DEFAULT]
.