Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的观点是这样的:
对于给定的 值session,我想检索 的唯一列表type。
session
type
function (doc) { if (doc.sesion) { emit([doc.sesion, doc.type], doc); } }
我应该如何查询视图?我需要创建另一个视图吗?
我知道我应该使用 include_docs 而不是在视图中发出文档,但暂时不用担心。
这样做:
?startkey=["session_value",""]&endkey=["session_value",{}]
但是,像这样重新格式化您的视图会更容易:
function (doc) { if (doc.sesion) { emit(doc.sesion, doc.type); } }
并像您提到的那样查询:
?key="session_value"&include_docs=true
要获得您可以使用的唯一类型集,请在没有(或,请参阅视图 API)的情况下reduce查询视图,如此处所述。请注意,这种方式您不能使用,因为您只能使用它(没有)。group=truegroup_levelgroup_level=exactstartkey=["YOUR_SESSION"]&endkey=["YOUR_SESSION",{}]include_docsmapreduce
reduce
group=true
group_level
group_level=exact
startkey=["YOUR_SESSION"]&endkey=["YOUR_SESSION",{}]
include_docs
map