References

You are able to store the reference of a collection or document, and use the reference when interacting with them.

const statesRef = nearDB.collection('states');

const nyRef = nearDB.collection('states').doc('ny');

Add a Document

Using set for document creation allows you to set the document id:

nearDB.collection('states').doc('ny').set({
    name: 'New York',
    population: 19849399,
    largestCity: 'New York City'
})

By calling add on the collection, a document id is auto-generated:

nearDB.collection('states').add({
    name: 'New York',
    population: 19849399,
    largestCity: 'New York City'
})

Update a Document

By using set, if the document does not exist, NearDB will create it. If it does exist, set will overwrite the whole document.

nearDB.collection('states').doc('ny').set({
    name: 'New York',
    population: 19849399,
    largestCity: 'New York City',
    eastCoast: true
})

If you wish to update fields within a document without overwriting all the data, you should use update:

nearDB.collection('states').doc('ny').update({
    eastCoast: true
})

To delete a value without overwriting the whole document, use the following helper constant:

nearDB.collection('states').doc('ny').update({
    eastCoast: NearDB.field.deleteValue
})

Delete a Document

By using delete, the whole document will be deleted from the bucket: