Cloudant:跨数据库搜索

Cloudant: Searching across databases

我有跨 2 个不同数据库的文档:水果、蔬菜。保持数据库分离对我来说更容易。

现在,假设我希望我的用户从这些数据库的任意组合中进行搜索。如果我 运行 跨三个数据库进行相同的查询并合并结果,它会工作吗?即:结果中的 order 字段是否具有绝对值,还是相对于其他结果?例如:

运行 我对水果数据库的查询:

{
  total_rows: 2,
  bookmark: "xxx",
rows: [
{
  id: "Apple",
  order: [
    2,
    220
  ],
  fields: {
    title: "Apple"
  }
},
{
  id: "pear",
  order: [
    1,
    4223
  ],
  fields: {
    title: "Pear"
  }
}
}

运行 我对蔬菜数据库的查询:

{
  total_rows: 1,
  bookmark: "xxx",
rows: [
{
  id: "brocolli",
  order: [
    1.5,
    3000
  ],
  fields: {
    title: "Brocolli"
  }
}
}

然后将结果结合起来产生

{
  total_rows: 2,
  bookmark: "xxx",
rows: [
{
  id: "Apple",
  order: [
    2,
    220
  ],
  fields: {
    title: "Apple"
  }
},
{
  id: "brocolli",
  order: [
    1.5,
    3000
  ],
  fields: {
    title: "Brocolli"
  }
},
{
  id: "pear",
  order: [
    1,
    4223
  ],
  fields: {
    title: "Pear"
  }
}
}

这行得通吗?还是只制作一个 foods 数据库更好?

无法使用 CouchDB 或 Cloudant 执行跨数据库连接。您将需要:

  • 将所有数据放在一个数据库中并查询
  • 拥有单独的数据库并将数据从每个数据库复制到单个数据库并查询
  • 拥有单独的数据库并在您的应用程序层中执行连接功能

我已将此问题添加到: