Node.js - collection.doc.set()

Set the value of a document.

import { collection } from '@nitric/sdk'

const profiles = collection('profiles').for('writing')

const drakesProfile = profiles.doc('Drake Mallard')

await drakesProfile.set({
  firstName: 'Drake',
  lastName: 'Mallard',
})

Parameters

  • Name
    document
    Required
    Required
    Type
    object
    Description

    The document to set on the key

Examples

Set a document

import { collection } from '@nitric/sdk'

const profiles = collection('profiles').for('writing')

const drakesProfile = profiles.doc('Drake Mallard')

await drakesProfile.set({
  firstName: 'Drake',
  lastName: 'Mallard',
})

Update a document

import { collection } from '@nitric/sdk'

const profiles = collection('profiles').for('reading', 'writing')

const drakesProfile = profiles.doc('Drake Mallard')

const existingProfile = await drakesProfile.get()

await drakesProfile.set({
  ...existingProfile,
  firstName: 'Drake',
})

See also