我在同一个couchdb数据库message
和user
中有2种不同的数据类型。它们如下所示:
// 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"
}
出于某种原因,在这种情况下不可能内联。我现在想要的是获取包含作者对象的所有消息的列表(如SQL SELECT * FROM messages JOIN users on message.author_id = message.id
)。
我读了这两篇文章:
所以我想使用include_docs=true
然后使用list
来很好地格式化它。我的messages
地图功能:
function(doc) {
if (doc.type == 'message') {
emit(doc._id, {_id: doc.author_id, entity: doc});
}
}
我使用网址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
},
...
我不知道该怎么做了。地图功能中没有完成编辑或删除。这是我的问题还是错误?
答案 0 :(得分:0)
尝试将地图js更改为更简单的形式以进行调试,例如
function(doc) {
if (doc.type == 'message') {
// emit(doc._id, {_id: doc.author_id, entity: doc});
emit(doc._id, { '_id': doc.author_id });
}
}