•  


WriteBatch - Documentation

WriteBatch

WriteBatch

new WriteBatch ()

A Firestore WriteBatch that can be used to atomically commit multiple write operations at once.

Methods

commit () → {Promise.<Array.< WriteResult >>}

Atomically commits all pending operations to the database and verifies all preconditions. Fails the entire write if any precondition is not met.

Returns:
Type Description
Promise.<Array.< WriteResult >>

A Promise that resolves when this batch completes.

Example
```
let writeBatch = firestore.batch();
let documentRef = firestore.doc('col/doc');

writeBatch.set(documentRef, {foo: 'bar'});

writeBatch.commit().then(() => {
  console.log('Successfully executed batch.');
});
```

create (documentRef, data) → { WriteBatch }

Create a document with the provided object values. This will fail the batch if a document exists at its location.

Parameters:
Name Type Description
documentRef DocumentReference

A reference to the document to be created.

data T

The object to serialize as the document.

Returns:
Type Description
WriteBatch

This WriteBatch instance. Used for chaining method calls.

Throws:

If the provided input is not a valid Firestore document.

Type
Error
Example
```
let writeBatch = firestore.batch();
let documentRef = firestore.collection('col').doc();

writeBatch.create(documentRef, {foo: 'bar'});

writeBatch.commit().then(() => {
  console.log('Successfully executed batch.');
});
```

delete (documentRef, precondition opt ) → { WriteBatch }

Deletes a document from the database.

Parameters:
Name Type Attributes Description
documentRef DocumentReference

A reference to the document to be deleted.

precondition Precondition <optional>

A precondition to enforce for this delete.

Properties
Name Type Attributes Description
lastUpdateTime Timestamp <optional>

If set, enforces that the document was last updated at lastUpdateTime. Fails the batch if the document doesn't exist or was last updated at a different time.

exists boolean <optional>

If set to true, enforces that the target document must or must not exist.

Returns:
Type Description
WriteBatch

This WriteBatch instance. Used for chaining method calls.

Example
```
let writeBatch = firestore.batch();
let documentRef = firestore.doc('col/doc');

writeBatch.delete(documentRef);

writeBatch.commit().then(() => {
  console.log('Successfully executed batch.');
});
```

set (documentRef, data, options opt ) → { WriteBatch }

Write to the document referred to by the provided DocumentReference . If the document does not exist yet, it will be created. If you pass SetOptions , the provided data can be merged into the existing document.

Parameters:
Name Type Attributes Description
documentRef DocumentReference

A reference to the document to be set.

data T | Partial.<T>

The object to serialize as the document.

options SetOptions <optional>

An object to configure the set behavior.

Properties
Name Type Attributes Description
merge boolean <optional>

If true, set() merges the values specified in its data argument. Fields omitted from this set() call remain untouched. If your input sets any field to an empty map, all nested fields are overwritten.

mergeFields Array.<(string| FieldPath )> <optional>

If provided, set() only replaces the specified field paths. Any field path that is no specified is ignored and remains untouched. If your input sets any field to an empty map, all nested fields are overwritten.

Returns:
Type Description
WriteBatch

This WriteBatch instance. Used for chaining method calls.

Throws:

If the provided input is not a valid Firestore document.

Type
Error
Example
```
let writeBatch = firestore.batch();
let documentRef = firestore.doc('col/doc');

writeBatch.set(documentRef, {foo: 'bar'});

writeBatch.commit().then(() => {
  console.log('Successfully executed batch.');
});
```

update (documentRef, dataOrField, …preconditionOrValues) → { WriteBatch }

Update fields of the document referred to by the provided DocumentReference . If the document doesn't yet exist, the update fails and the entire batch will be rejected.

The update() method accepts either an object with field paths encoded as keys and field values encoded as values, or a variable number of arguments that alternate between field paths and field values. Nested fields can be updated by providing dot-separated field path strings or by providing FieldPath objects.

A Precondition restricting this update can be specified as the last argument.

Parameters:
Name Type Attributes Description
documentRef DocumentReference

A reference to the document to be updated.

dataOrField UpdateData | string | FieldPath

An object containing the fields and values with which to update the document or the path of the first field to update.

preconditionOrValues Precondition | * | string | FieldPath <repeatable>

An alternating list of field paths and values to update or a Precondition to restrict this update.

Returns:
Type Description
WriteBatch

This WriteBatch instance. Used for chaining method calls.

Throws:

If the provided input is not valid Firestore data.

Type
Error
Example
```
let writeBatch = firestore.batch();
let documentRef = firestore.doc('col/doc');

writeBatch.update(documentRef, {foo: 'bar'});

writeBatch.commit().then(() => {
  console.log('Successfully executed batch.');
});
```

- "漢字路" 한글한자자동변환 서비스는 교육부 고전문헌국역지원사업의 지원으로 구축되었습니다.
- "漢字路" 한글한자자동변환 서비스는 전통문화연구회 "울산대학교한국어처리연구실 옥철영(IT융합전공)교수팀"에서 개발한 한글한자자동변환기를 바탕하여 지속적으로 공동 연구 개발하고 있는 서비스입니다.
- 현재 고유명사(인명, 지명등)을 비롯한 여러 변환오류가 있으며 이를 해결하고자 많은 연구 개발을 진행하고자 하고 있습니다. 이를 인지하시고 다른 곳에서 인용시 한자 변환 결과를 한번 더 검토하시고 사용해 주시기 바랍니다.
- 변환오류 및 건의,문의사항은 juntong@juntong.or.kr로 메일로 보내주시면 감사하겠습니다. .
Copyright ⓒ 2020 By '전통문화연구회(傳統文化硏究會)' All Rights reserved.
 한국   대만   중국   일본