我有一个数据库,其中包含用户之间的聊天消息(每个用户1个消息副本:1个发送者消息和1个接收者消息)。使用2台计算机(1个linux和1个窗口)运行Couchbase server 2.0集群。
我使用这样的地图功能来检索用户之间的消息:
function (doc) {
if (doc.type == "msg"){
emit([doc.OwnerId, doc.SndrId, doc.Date], {"Date":doc.Date, "OwnerId":doc.OwnerId, "RcptId":doc.RcptId, "SndrId":doc.SndrId, "Text":doc.Text, "Unread":doc.Unread, "id": doc.id, "type":doc.type});
emit([doc.OwnerId, doc.RcptId, doc.Date], {"Date":doc.Date, "OwnerId":doc.OwnerId, "RcptId":doc.RcptId, "SndrId":doc.SndrId, "Text":doc.Text, "Unread":doc.Unread, "id": doc.id, "type":doc.type});
}
}
因此,如果我尝试从开始接收一些消息(按日期排序降序),我使用了这样的启动键& endkey:
startkey=[1,2,{}]
endkey=[1,2,0]
但是这样我得不到所有的消息。要获取我需要使用的所有消息
startkey=[1,2,{}]
endkey=[1,2]
这是一个例子。对于带零的键:
{"total_rows":1106,"rows":[
{"id":"msg_8aaca454-5580-4e49-a081-918d8eaba9d6","key":[8,75,1342200837278],"value":{"Date":1342200837278,"OwnerId":8,"RcptId":8,"SndrId":75,"Text":"02","Unread":false,"id":"8aaca454-5580-4e49-a081-918d8eaba9d6","type":"msg"}},
{"id":"msg_49417551-bdc9-477b-b8c2-1f36051bb930","key":[8,75,1342199880920],"value":{"Date":1342199880920,"OwnerId":8,"RcptId":75,"SndrId":8,"Text":"4","Unread":false,"id":"49417551-bdc9-477b-b8c2-1f36051bb930","type":"msg"}},
{"id":"msg_2724f077-1e76-4fbc-9a4b-f34cb71e2db0","key":[8,75,1342108023448],"value":{"Date":1342108023448,"OwnerId":8,"RcptId":75,"SndrId":8,"Text":"55","Unread":false,"id":"2724f077-1e76-4fbc-9a4b-f34cb71e2db0","type":"msg"}},
{"id":"msg_9cc91327-4ba3-45b5-ab64-f2ca63510e8d","key":[8,75,1341413650113],"value":{"Date":1341413650113,"OwnerId":8,"RcptId":75,"SndrId":8,"Text":"3","Unread":false,"id":"9cc91327-4ba3-45b5-ab64-f2ca63510e8d","type":"msg"}},
{"id":"msg_9a386663-8a2b-42d9-ae30-0634a98fe574","key":[8,75,1341413648335],"value":{"Date":1341413648335,"OwnerId":8,"RcptId":75,"SndrId":8,"Text":"1","Unread":false,"id":"9a386663-8a2b-42d9-ae30-0634a98fe574","type":"msg"}}
]
}
键不为零:
{"total_rows":1106,"rows":[
{"id":"msg_dc4b7758-1f0e-491c-a80d-bf3124dc0ad7","key":[8,75,1342200856186],"value":{"Date":1342200856186,"OwnerId":8,"RcptId":8,"SndrId":75,"Text":"03","Unread":false,"id":"dc4b7758-1f0e-491c-a80d-bf3124dc0ad7","type":"msg"}},
{"id":"msg_8aaca454-5580-4e49-a081-918d8eaba9d6","key":[8,75,1342200837278],"value":{"Date":1342200837278,"OwnerId":8,"RcptId":8,"SndrId":75,"Text":"02","Unread":false,"id":"8aaca454-5580-4e49-a081-918d8eaba9d6","type":"msg"}},
{"id":"msg_b2fe9ca0-aa28-41a6-ab3c-09ece6a5e14a","key":[8,75,1342200787811],"value":{"Date":1342200787811,"OwnerId":8,"RcptId":8,"SndrId":75,"Text":"01","Unread":true,"id":"b2fe9ca0-aa28-41a6-ab3c-09ece6a5e14a","type":"msg"}},
{"id":"msg_49417551-bdc9-477b-b8c2-1f36051bb930","key":[8,75,1342199880920],"value":{"Date":1342199880920,"OwnerId":8,"RcptId":75,"SndrId":8,"Text":"4","Unread":false,"id":"49417551-bdc9-477b-b8c2-1f36051bb930","type":"msg"}},
{"id":"msg_0d7dc822-b76c-42f9-87ba-3dc486100526","key":[8,75,1342180778835],"value":{"Date":1342180778835,"OwnerId":8,"RcptId":75,"SndrId":8,"Text":"Gcgjvv6gvvbnbvvbh B2B bb cb B2B","Unread":false,"id":"0d7dc822-b76c-42f9-87ba-3dc486100526","type":"msg"}},
{"id":"msg_6b26a65f-68e1-4728-87f1-59ea5e0f0c5d","key":[8,75,1342114611144],"value":{"Date":1342114611144,"OwnerId":8,"RcptId":75,"SndrId":8,"Text":"546546546546546546546546546546","Unread":false,"id":"6b26a65f-68e1-4728-87f1-59ea5e0f0c5d","type":"msg"}},
{"id":"msg_f89b09ac-ccf1-4958-85c0-259b0b68752b","key":[8,75,1342108583566],"value":{"Date":1342108583566,"OwnerId":8,"RcptId":75,"SndrId":8,"Text":"123","Unread":false,"id":"f89b09ac-ccf1-4958-85c0-259b0b68752b","type":"msg"}},
{"id":"msg_2724f077-1e76-4fbc-9a4b-f34cb71e2db0","key":[8,75,1342108023448],"value":{"Date":1342108023448,"OwnerId":8,"RcptId":75,"SndrId":8,"Text":"55","Unread":false,"id":"2724f077-1e76-4fbc-9a4b-f34cb71e2db0","type":"msg"}},
{"id":"msg_9cc91327-4ba3-45b5-ab64-f2ca63510e8d","key":[8,75,1341413650113],"value":{"Date":1341413650113,"OwnerId":8,"RcptId":75,"SndrId":8,"Text":"3","Unread":false,"id":"9cc91327-4ba3-45b5-ab64-f2ca63510e8d","type":"msg"}},
{"id":"msg_847b2901-95e3-49b9-8756-e495872558a8","key":[8,75,1341413649161],"value":{"Date":1341413649161,"OwnerId":8,"RcptId":75,"SndrId":8,"Text":"2","Unread":false,"id":"847b2901-95e3-49b9-8756-e495872558a8","type":"msg"}}
]
}
有人可以解释为什么它不会在第一种情况下绑定所有消息吗?
答案 0 :(得分:1)
感谢来自couchbase团队的Filipe Manana,他回答了这个问题。 此问题是由64位平台上的Erlang OTP R14B03(以及所有先前版本)引起的。
这是Filipe的提交修复了这个错误https://github.com/erlang/otp/commit/03d8c2877342d5ed57596330a61ec0374092f136
有关详细信息,请参阅http://www.couchbase.com/forums/thread/couchbase-view-not-rerurning-all-values
答案 1 :(得分:0)
NB CouchDB和CouchBase与Membase和MySQL =类似,以相同的前缀开头。最好不要让他们困惑!
这可能与通过ASCII(您期望的)与通过unicode整理进行排序有关。这里有一些更多的信息http://wiki.apache.org/couchdb/View_collation,但这适用于CouchDB,而不是CouchBase。也许这有帮助吗?