include_docs=true的CouchDB视图产生doc:null
CouchDB view with include_docs=true yields doc: null
我在同一个couchdb数据库中有两种不同的数据类型,message
和user
。它们看起来如下:
// message
{
"_id": "test__032142f981b1bddd00bb9a0161688480",
"_rev": "8-d1b19caabac334c4b9e9eb1f0b0b8986",
"created": "2011-12-27T23:48:17.940699Z",
"text": "Omnis quam nesciunt dolor quaerat.",
"author_id": "test__d3f62f343144dfef8fd112946da9c1b3",
"type": "message",
"subject": "Some text"
"recipients": [
"user id 1",
"user id 2",
]
}
//user
{
"_id": "test__d3f62f343144dfef8fd112946da9c1b3",
"_rev": "12-88206492cc5274248aa5a64ff6a49b9a",
"type": "user",
"profile": {
"callname": "User name",
"fullname": "User name",
"profile_text": "Blah blah",
"urls": [
{
"url": "http://www.example.org",
"description": "CV, Blog, Pictures, Research, Links",
"label": "Homepage"
}
],
"profile_image_url": "http://localhost:5000/static/img/profiles/2e38f9fdd9e458eb4db0e7bb3b8e9576.jpg"
},
"registration_date": "2014-08-14T20:07:28Z",
"verified": "none",
"preferences": {
"lang": "en"
},
"last_login": "2014-08-14T20:07:28Z",
"email": "user@example.org"
}
出于某些原因,在这种情况下不可能进行内联。我现在想要的是获得包含author对象的所有消息的列表(如SQL SELECT * FROM messages JOIN users on message.author_id = message.id
)。
我读过这两篇文章:
- http://www.cmlenz.net/archives/2007/10/couchdb-joins
- http://wiki.apache.org/couchdb/Introduction_to_CouchDB_views#Linked_documents
所以我想使用include_docs=true
,然后使用list
来很好地格式化它。我的messages
地图功能:
function(doc) {
if (doc.type == 'message') {
emit(doc._id, {_id: doc.author_id, entity: doc});
}
}
我使用URL http://localhost:5984/dedri/_design/dedri/_view/messages?include_docs=true
对此进行调用。但我明白了,doc: null
:
{
"total_rows": 34,
"offset": 0,
"rows": [
{
"id": "test__032142f981b1bddd00bb9a0161688480",
"key": "test__032142f981b1bddd00bb9a0161688480",
"value": {
"_id": "test__d3f62f343144dfef8fd112946da9c1b3",
"entity": {
"_id": "test__032142f981b1bddd00bb9a0161688480",
"_rev": "8-d1b19caabac334c4b9e9eb1f0b0b8986",
"created": "2011-12-27T23:48:17.940699Z",
"text": "Omnis quam nesciunt dolor quaerat.",
"version": "0.1",
"author_id": "test__d3f62f343144dfef8fd112946da9c1b3",
"type": "message",
"subject": "Some text"
}
},
"doc": null
},
...
我不知道该怎么办了。地图功能中没有进行编辑或删除。这是我的问题还是bug?
尝试将map js更改为更简单的形式进行调试,例如
function(doc) {
if (doc.type == 'message') {
// emit(doc._id, {_id: doc.author_id, entity: doc});
emit(doc._id, { '_id': doc.author_id });
}
}
相关文章:
- 如何使用WCF服务和javascript表单post上传.doc文件
- 数组在递归方法中设置为null
- 字符串在将其传递给另一个活动Android JavaScript时读取Null
- 无法获取属性'selectedIndex'的未定义引用或null引用
- Meteor方法在客户端返回null,在客户端运行的相同方法返回正确的值
- 来自文本输入null的html javascript变量
- delete在Object上效率低下,但在DOM Element's的数据属性,与null out相比
- php代码在textbox更改事件上显示null
- 相同的RegExp返回不同的结果-第一次是正确的结果,第二次是null
- 在php中提交数据时,如果某些值为null,而某些值为非null,如何进行查询
- 未捕获的类型错误:无法读取属性'addEventListener'的null chrome扩展名
- 为什么localStorage[“..”]未定义,而localStorage.getItem(“..”)为null
- ajax在输入等于null时进行检查
- html+javascript:如何在某些条件下禁用dropdownlist中的null选项
- 未捕获的类型错误:无法读取属性'状态'在react中为null
- contentWindow.document.body is null
- 在经过DATE验证的列中创建null值
- 为什么是文档.旧版应用程序中的DOM-object.properties为null
- include_docs=true的CouchDB视图产生doc:null
- 打开Web分析与Node.JS Web应用程序.获取错误'TypeError: doc is null'