collection.doc.set()

Sets 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


document required object

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('writing');
const drakesProfile = profiles.doc('Drake Mallard');
const existingProfile = await drakesProfile.get();
await drakesProfile.set({
...existingProfile,
firstName: 'Drake',
});

See also