问题
In the CouchDB GUI, when I add a new document the _id
field is the only field that appears by default. I must manually click "Add field" for each other field I want to add. This gets repetitive when I know every document in that particular database needs those fields. Is it possible to customize a database, so that when I create a new document in that database it has more than the _id
field by default?
回答1:
I don't think it's possible to have predefined fields in CouchDB, I would probebly solve it by using a update function:
function(doc, req) {
if (!doc) {
return [null, JSON.stringify({
status: 400,
message: 'nodoc'
})];
}
doc.foo = "";
doc.bar = "";
return [doc, JSON.stringify({
doc: doc,
status: 200,
message: 'updated'
})];
}
And call it with curl -X PUT http://127.0.0.1:5984/db/_design/foo/_update/bar/_id
for all documents I create.
来源:https://stackoverflow.com/questions/32937655/couchdb-pre-filled-fields-when-adding-new-documents