我将如何为 cloudant nosql 中数组的一部分的元素创建索引?
How would I create an index for an element that's part of an array in cloudant nosql?
假设有如下文档
{
_id:1234,
pages:[
{"name":"a","content":"a1"},
{"name":"b","content":"b1"},
{"name":"c","content":"c1"},
]
}
如何创建主索引,以便将 "name" 作为字段进行查询?
您可以创建一个 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);
}
});
}
}
假设有如下文档
{
_id:1234,
pages:[
{"name":"a","content":"a1"},
{"name":"b","content":"b1"},
{"name":"c","content":"c1"},
]
}
如何创建主索引,以便将 "name" 作为字段进行查询?
您可以创建一个 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);
}
});
}
}