MySQL INSTR像在mongodb中的操作 [英] Mysql INSTR like operation in mongodb

查看:129
本文介绍了MySQL INSTR像在mongodb中的操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里完全是mongo的新手.

Completely new to mongo here.

我的mysql表中有以下字段:

I have following fields in on of my mysql tables:

id (BIGINT), text (LONGTEXT) #this would contain a long description

我希望将项目从Mysql更改为MongoDB,但在此之前,有一个非常关键的查询需要解决.

I am hoping to change my project from Mysql to MongoDB, but before I do that there is very crucial query that needs to be resolved.

我当前的查询在描述中查找各种术语并返回所有ID,例如

My current query looks for various terms in the description and returns all ids, e.g.

select id from <table> where instr(<table>.text, 'value') or instr(<table>.text, 'value2)

是否有可能在Mongo中重新创建?如果是这样怎么办?现在使用$ or或$ in似乎需要在文档的某种数组中具有这些特定值.

Is it possible for this to be recreated in Mongo? if so how? right now using either the $or or $in seems that I need to have those specific values in some kind of an array in my document.

推荐答案

MongoDB目前不支持全文本搜索.

MongoDB does not natively support full text search at the moment.

您可以使用正则表达式,但是会很慢(由于除非使用索引,否则不使用索引).

You could use regular expressions but it would be slow (due to not using indexes unless they are rooted).

查询如下:

db.collection.find({ $or: [{description: /value1/}, {description: /value2/}] })

您可以进行一些预处理,以将每个单词插入可搜索的关键字数组中,但是如果文本真的很长,您可能不想走这条路.

You could do some preprocessing to insert each word into a searchable array of keywords but if the text is really long you probably don't want to go this route.

这篇关于MySQL INSTR像在mongodb中的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆