@textile/hub > Client > save
Client.save() method
Saves changes to an existing model instance in the given store.
Signature:
save(threadID: ThreadID, collectionName: string, values: any[]): Promise<void>;
Parameters
Parameter | Type | Description |
---|---|---|
threadID | ThreadID | the ID of the database |
collectionName | string | The human-readable name of the model to use. |
values | any[] | An array of model instances as JSON/JS objects. Each model instance must have a valid existing _id property. |
Returns:
Promise<void>
Example
Update an existing instance
import {Client, ThreadID, Where} from '@textile/hub'
interface Astronaut {
name: string
missions: number
_id: string
}
async function updateBuzz (client: Client, threadID: ThreadID) {
const query = new Where('name').eq('Buzz')
const result = await client.find<Astronaut>(threadID, 'astronauts', query)
if (result.length < 1) return
const buzz = result[0]
buzz.missions += 1
return await client.save(threadID, 'astronauts', [buzz])
}