索引和查询数组,使用cloudant和couchdb 2.0的芒果查询

编程入门 行业动态 更新时间:2024-10-11 11:13:10
本文介绍了索引和查询数组,使用cloudant和couchdb 2.0的芒果查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我具有以下数据库结构:

I have the following db structure:

{"_id": "0096874","genre": ["Adventure","Comedy", "Sci-Fi" ]} {"_id": "0099088","genre": ["Comedy", "Sci-Fi", "Western"]}

并希望像在mongodb中一样进行查询

and like to query it like I could do in mongodb

db.movies.find({genre: {$in: ["Comedy"]}})

当我在整个数据库中使用文本索引时,它可以工作,但这似乎非常浪费:

It works when i use a text index for the whole database, but that seems very wasteful:

// index { "index": {}, "type": "text" } //query { "selector": { "genre": { "$in": ["Comedy"] } }, "fields": [ "_id", "genre" ] }

以下索引不起作用:

{ "index": { "fields": [ "genre" ] }, "type": "json" }

什么是cloudant查询的正确索引,而不是整个数据库的索引? 谢谢您的帮助

What is the correct index for cloudant query, which does not index the whole db? Thanks for your help

推荐答案

您几乎完全正确.您的索引正确,但是您需要使用选择器来获取所有ID https ://cloudant/blog/mango-json-vs-text-indexes/.

You had it almost correct. Your index is right, but you need to throw in a selector to get all IDs cloudant/blog/mango-json-vs-text-indexes/.

正如Tony所说,这不是解决方案性能的好方法,

This isn't a great solution performance-wise, as Tony says,

之所以可行,是因为,Mango对所有文档执行上述$ in操作作为过滤机制.正如我们在上一节有关JSON语法的结论中所看到的,上述查询的性能折衷在于,它本质上执行完整索引扫描,然后应用过滤器.

{ "selector": { "_id": { "$gt": null }, "genre": { "$in": ["Western"] } }, "fields": [ "_id", "genre" ], "sort": [ { "_id": "asc" } ] }

更多推荐

索引和查询数组,使用cloudant和couchdb 2.0的芒果查询

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

发布评论

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

>www.elefans.com

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