| 72 | } |
| 73 | |
| 74 | async init() { |
| 75 | firebase() |
| 76 | .firestore() |
| 77 | .collection('users') |
| 78 | .add({ |
| 79 | first: 'Ada', |
| 80 | last: 'Lovelace', |
| 81 | born: 1815, |
| 82 | }) |
| 83 | .then((docRef) => { |
| 84 | console.log('Document written with ID: ', docRef.id); |
| 85 | }) |
| 86 | .catch((error) => { |
| 87 | console.error('Error adding document: ', error); |
| 88 | }); |
| 89 | |
| 90 | const geo = new GeoPoint(10, -10); |
| 91 | firebase() |
| 92 | .firestore() |
| 93 | .collection('geo') |
| 94 | .add({ |
| 95 | thing: 'it', |
| 96 | geo, |
| 97 | }) |
| 98 | .then((docRef) => { |
| 99 | console.log('Geo Document written with ID: ', docRef.id); |
| 100 | }) |
| 101 | .catch((error) => { |
| 102 | console.error('Error adding geo document: ', error); |
| 103 | }); |
| 104 | |
| 105 | firebase() |
| 106 | .firestore() |
| 107 | .collection('items') |
| 108 | .get() |
| 109 | .then((items) => { |
| 110 | console.log(items.docs[0].data()); |
| 111 | }); |
| 112 | |
| 113 | const exampleDoc = firebase().firestore().collection('things').doc('exampleDoc'); |
| 114 | const exampleDoc2 = firebase().firestore().collection('things').doc('exampleDoc2'); |
| 115 | |
| 116 | firebase() |
| 117 | .firestore() |
| 118 | .batch() |
| 119 | .set(exampleDoc, { |
| 120 | message: 'Hello doc', |
| 121 | }) |
| 122 | .set(exampleDoc2, { |
| 123 | date: new Date(), |
| 124 | }) |
| 125 | .commit() |
| 126 | .then(() => {}) |
| 127 | .catch((error) => { |
| 128 | console.error(error); |
| 129 | }); |
| 130 | } |
| 131 | |