Reputation: 622
Im using cloudFirestore as the database and i want to update a Field that lives in a document.
collection :users.
document:user.
field:website.
so for that i did like so :
db.doc('/users/user').update({website:'user.com'});
but iam getting this Error :
No document to update: projects/social-app-12282/databases/(default)/documents/users/user'
Can someone tell me wht this happen,thank you in advance
Edit:
you can see here that i have a docment called user
Upvotes: 2
Views: 5073
Reputation: 4660
For you to update a document in Firestore, the structure of the update is a little bit different in relation to yours. As per the documentation - accessible here - you need to select the collection and then, the document you want to update. The code would be something like the below one:
var usersRef = db.collection("users").doc("user");
// Set the "user" field of the city 'DC'
return usersRef.update({
"website": "user.com"
})
.then(function() {
console.log("Document successfully updated!");
})
.catch(function(error) {
// The document probably doesn't exist.
console.error("Error updating document: ", error);
});
A simplified version would be:
db.collection("users").doc("user").update({
"website": "user.com"
})
.then(function() {
console.log("Document successfully updated!");
});
While this is untested code, I believe it should help you with understanding on how to update the values and as a starting point. You can get more examples from the official documentation as well.
Upvotes: 1