# Update and remove NoSQL documents

> Change documents with update() and where(), delete them with remove(), and read how many were affected.

Framework: total5
Product: Total.js 5 (total5@0.0.19)
Language: en
Content-SHA256: 894a7fd501ee19c762e00adca86b75172e9c997c4b994da7eb426d66e2a487d7
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: total5-installed@total5@0.0.19
Review: not-recorded

`update(data)` and `remove()` work like `find()`: add the conditions with `.where()` and finish with `.callback(function(err, count) {})`. The callback receives the number of documents that were changed or removed. **Always add a condition**: without one the operation applies to every document.

`update(data)` merges the fields of `data` into the matching documents. Use `read()` to get a single document.

```js controllers/tasks.js
exports.install = function() {
	ROUTE('POST /tasks/', create);
	ROUTE('PATCH /tasks/{id}/', done);
	ROUTE('DELETE /tasks/{id}/', remove);
	ROUTE('GET /tasks/{id}/', read);
};

function create($) {
	var task = { id: $.body.id, title: $.body.title, done: false };
	NOSQL('tasks').insert(task).callback(() => $.json(task));
}

function done($) {
	NOSQL('tasks').update({ done: true }).where('id', $.params.id).callback((err, count) => $.json({ updated: count }));
}

function remove($) {
	NOSQL('tasks').remove().where('id', $.params.id).callback((err, count) => $.json({ removed: count }));
}

function read($) {
	NOSQL('tasks').read().where('id', $.params.id).callback((err, response) => $.json(response || { missing: true }));
}
```
