假设有一个文档,如下所示
{
_id:1234,
pages:[
{"name":"a","content":"a1"},
{"name":"b","content":"b1"},
{"name":"c","content":"c1"},
]
}
我将如何创建主索引,以便将“名称”作为字段进行查询?
您可以创建一个 map-reduce 视图来实现您想要的:
function(doc) {
if (doc && doc.pages) {
doc.pages.forEach(function (row) {
if (row.name) {
emit(row.name, 1);
// or if you want to lookup the content part, use
// emit(row.name, row.content);
}
});
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句