CouchDB:添加新文档时要预填字段吗? [英] CouchDB: Pre-filled fields when adding new documents?
问题描述
在CouchDB GUI中,当我添加新文档时, _id
字段是默认情况下唯一显示的字段.我必须为要添加的其他每个字段手动单击添加字段".当我知道特定数据库中的每个文档都需要这些字段时,这种情况就会重复出现.是否可以自定义数据库,以便当我在该数据库中创建一个新文档时,默认情况下它具有比 _id
字段更多的字段?
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?
推荐答案
我认为CouchDB中不可能有预定义的字段,我会尝试通过使用update函数来解决:
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'
})];
}
然后对我创建的所有文档,使用 curl -X PUT http://127.0.0.1:5984/db/_design/foo/_update/bar/_id
调用它.
And call it with curl -X PUT http://127.0.0.1:5984/db/_design/foo/_update/bar/_id
for all documents I create.
这篇关于CouchDB:添加新文档时要预填字段吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!