55 *
66 * @private
77 * @param {string } path the path where the document will be written
8- * @param {string } documentId the document's ID in Firestore
98 * @param {object } fields the document's fields
109 * @param {string } request the Firestore Request object to manipulate
1110 * @return {object } the Document object written to Firestore
1211 */
1312function createDocument_ ( path , fields , request ) {
14- const pathDoc = getDocumentFromPath_ ( path )
15- const firestoreObject = createFirestoreDocument_ ( fields )
16- const documentId = pathDoc [ 1 ]
17-
18- if ( documentId ) {
19- request . addParam ( 'documentId' , documentId )
20- }
21-
22- const newDoc = request . post ( pathDoc [ 0 ] , firestoreObject )
23- return unwrapDocumentFields_ ( newDoc )
13+ request . addParam ( 'currentDocument.exists' , false )
14+ return updateDocument_ ( path , fields , request )
2415}
2516
2617/**
@@ -30,7 +21,7 @@ function createDocument_ (path, fields, request) {
3021 * @param {string } path the path of the document to update
3122 * @param {object } fields the document's new fields
3223 * @param {string } request the Firestore Request object to manipulate
33- * @param {boolean } if true, the update will use a mask. i.e. true: updates only specific fields, false: overwrites document with specified fields
24+ * @param {boolean } mask if true, the update will use a mask. i.e. true: updates only specific fields, false: overwrites document with specified fields
3425 * @return {object } the Document object written to Firestore
3526 */
3627function updateDocument_ ( path , fields , request , mask ) {
0 commit comments