Yes you can do that with an update handler. You're on the right track. Here are the 3 cases:
Create a doc without specifying an id
The path taken is !doc && !req.id
.
That's your example. Instead of returning null
, you should build a new document and return it. You can use req.uuid
to populate the _id
. For instance:
return [{_id : req.uuid, timestamp : new Date().getTime()}, 'created new doc'];
Create a doc with a given id
The path taken is !doc && req.id
. You got this one right.
Update an existing doc
The path taken is doc
. You got this one right.