create method
Create a document with the provided object values. This will fail the write if a document exists at its location.
data
: An object that contains the fields and data to serialize as the document.
Throws if the provided input is not a valid Firestore document.
Returns a Future that resolves with the write time of this create.
final documentRef = firestore.collection('col').doc();
documentRef.create({foo: 'bar'}).then((res) {
print('Document created at ${res.updateTime}');
}).catch((err) => {
print('Failed to create document: ${err}');
});
Implementation
Future<WriteResult> create(T data) async {
final writeBatch = WriteBatch._(this.firestore)..create<T>(this, data);
final results = await writeBatch.commit();
return results.single;
}