Reputation: 13357
I'm already testing the new Firestore
API, and I'm having some problems regarding to the documentation and the update
call.
I'm trying to update a no existing document and I'm recieving an error. Obviously this is fine, because the documentation say that the update
call will fail if the DocumentReference
doesn't exist. However, reading the official documentation I see the next block of code:
// Update the population, creating the document if it
// does not already exist.
db.collection("cities").document("Beijing").update(
new UpdateOptions().createIfMissing(),
"population",
21500000);
I'm trying to replicate this, but I don't find the UpdateOptions
call. Also, checking the different overrides methods of update
these is no constructor for such call.
I'm using the 11.4.2
version of Firebase. Any idea of what is happening?
Upvotes: 3
Views: 1476
Reputation: 7870
The Firestore API changed just before the beta launch and UpdateOptions no longer exists. If you'd like to merge fields into a document that may or may not exist use set
, like so:
Map<String, Object> data = new HashMap<>();
data.put("population", 21500000);
db.collection("cities").document("Beijing")
.set(data, SetOptions.merge());
Unfortunately, our translated documentation is currently out of date, please refer to the English version for now.
Upvotes: 7