1let data = {
2 name: 'Los Angeles',
3 state: 'CA',
4 country: 'USA'
5};
6
7// Add a new document in collection "cities" with ID 'LA'
8let setDoc = db.collection('cities').doc('LA').set(data);
1let washingtonRef = db.collection('cities').doc('DC');
2
3// Atomically add a new region to the "regions" array field.
4let arrUnion = washingtonRef.update({
5 regions: admin.firestore.FieldValue.arrayUnion('greater_virginia')
6});
7// Atomically remove a region from the "regions" array field.
8let arrRm = washingtonRef.update({
9 regions: admin.firestore.FieldValue.arrayRemove('east_coast')
10});
1var docData = {
2 stringExample: "Hello world!",
3 booleanExample: true,
4 numberExample: 3.14159265,
5 dateExample: firebase.firestore.Timestamp.fromDate(new Date("December 10, 1815")),
6 arrayExample: [5, true, "hello"],
7 nullExample: null,
8 objectExample: {
9 a: 5,
10 b: {
11 nested: "foo"
12 }
13 }
14};
15db.collection("data").doc("one").set(docData).then(() => {
16 console.log("Document successfully written!");
17});