I'm working on a Flutter app where I want to save entries into Firebase Firestore under a user-specific subcollection. The data seems to be added successfully to the device, but it never appears in the Firestore Console. Instead, it looks like the data is only cached locally on the device, and I keep seeing the following message in the logs:
[WatchStream]: (be43146) Stream closed with status: Status{code=NOT_FOUND, description=The database (default) does not exist for project <project_name> Please visit https://console.cloud.google.com/datastore/setup?project=<project_name> to add a Cloud Datastore or Cloud Firestore database. , cause=null}.
Here’s what I’ve tried:
google-services.json
for Android).Firebase.initializeApp()
.service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth != null;
}
}
}
Here’s the function I use to add data to Firestore:
void addUrl() async {
if (urlController.text.isNotEmpty) {
final currentUser = auth.currentUser;
if (currentUser != null) {
await firestore
.collection('users')
.doc(currentUser.uid)
.collection('urls')
.add({
'url': urlController.text,
'timestamp': FieldValue.serverTimestamp(),
});
// Clear the text field after adding it to Firestore
urlController.clear();
} else {
developer.log("User is not signed in");
}
}
}
Despite successfully calling this function and clearing the text field, the data only appears to be cached locally on the device. The Firestore Console remains empty.
The error message says:
The database (default) does not exist for project <project_name>
So you'll want to click the link in the error message (which ensures it opens the right project), and make sure that you have a default database (so one named (default)
) in there. If not, you'll need to create one for the error to go away.