我有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:跨数据库搜索
发布评论