MST

星途 面试题库

面试题:CouchDB中文档嵌套数据的基本查询处理

假设在CouchDB中有一个文档,结构如下:{"_id":"example1","name":"John","hobbies":[{"name":"reading","books":["book1","book2"]},{"name":"sports","types":["basketball","running"]}]}。请写出查询此人所有爱好名称的CouchDB视图函数。
25.8万 热度难度
数据库CouchDB

知识考点

AI 面试

面试题答案

一键面试
function (doc) {
  if (doc.hobbies) {
    doc.hobbies.forEach(function (hobby) {
      emit(null, hobby.name);
    });
  }
}