CouchDB附件的自定义属性

时间:2010-12-29 18:39:43

标签: couchdb attachment

我试图在单个CouchDB文档中存储多个独立附件,并为每个附件分配任意属性(即描述)。这样做会有约定吗?据我所知,我不能直接在_attachments结构中插入它们。提前谢谢!

1 个答案:

答案 0 :(得分:8)

您无法直接修改_attachments中的任何内容,因为它保留供CouchDB使用。但是,使用attachment_attributes中的相同键(附件名称)将任意属性存储在_attachments等成员中是非常合理的。例如:

{
  "_attachments": {
    "foo.bar": ...,
    "xxx.yyy": ...
  },
  "attachment_attributes": {
    "foo.bar": {
      "description": "blah blah"
    },
    "xxx.yyy": {
      "description": "blah blah"
    }
  }
}