Cloudant:跨数据库搜索

编程入门 行业动态 更新时间:2024-10-27 19:25:46
本文介绍了Cloudant:跨数据库搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I have documents across 2 different databases: fruits, vegetables. It's easier for me to keep the databases separated.

现在,假设我希望我的用户从这些数据库的任何组合中进行搜索。如果我在三个数据库中运行相同的查询并将结果合并,是否可以工作。也就是说:结果中的 order 字段是否具有绝对值,或者相​​对于其他结果?例如:

Now, suppose I want my user to search from any combination of these databases. Would it work if I run the same query across the three databases, and merge the result. That is: does the order field in a results have an absolute value, or is it relative to the other results? For example:

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

Run my query on fruits db:

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

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

Run my query on vegetable database:

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

然后带来结果在一起产生

Then bringing the results together to produce

{ 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 数据库更好?

Would this work? Or is it better to just make a single foods database?

推荐答案

无法使用CouchDB或Cloudant在数据库之间执行联接。您将需要:

It is not possible to perform joins across databases using CouchDB or Cloudant. You will need to either:

  • 将所有数据放入单个数据库中,并查询
  • 具有独立的数据库,并将每个数据库中的数据复制到单个数据库,并查询
  • 具有独立的数据库并在应用程序层中执行联接功能

我已将此问题添加到:如何在Cloudant / CouchDB中使用我的SQL知识?

I've added this question to: How can I use my sql knowledge with Cloudant/CouchDB?

更多推荐

Cloudant:跨数据库搜索

本文发布于:2023-10-30 03:50:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1541669.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库   Cloudant

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!