简体   繁体   English

MongoDB 通配符查询使用 Grails 花费太多时间

[英]MongoDB WildCard query taking too much time using Grails

  • MongoDB v4.0.2 MongoDB v4.0.2
  • Grails 3.3.5圣杯 3.3.5

I've more than 20 Millions of records stored in a collection.我在一个集合中存储了超过 2000 万条记录。 I'm trying to wildcard search in that collection like as follows...我正在尝试在该集合中进行通配符搜索,如下所示...

def personList = Person.collection.find(['vehicleNumber': ['$regex':/.*GJ18AD.*/] ]).sort(["datetime":-1])

Index on Person Collection人物收藏索引

db.person.getIndexes()
{
    "v" : 2,
    "key" : {
        "vehicleNumber" : 1
    },
    "name" : "vehicleNumber_1",
    "ns" : "analytics.person",
    "weights" : {
        "numberPlate" : 1
    },
    "default_language" : "english",
    "language_override" : "language",
    "textIndexVersion" : 3
}

Is there any other way for the wildcard search?通配符搜索还有其他方法吗?

There is no changes required in the indexing.索引不需要更改。 But the minor change in the filter Object which I'm passing to the collection.但是我传递给集合的过滤器对象中的微小变化。

Previously, I was using following filter object syntax:以前,我使用以下过滤器对象语法:

 def personList = Person.collection.find(['vehicleNumber': ['$regex':/.*GJ18AD.*/] ]).sort(['datetime':-1])

Then I've change only the regex in the above syntax:然后我只更改了上述语法中的正则表达式:

def personList = Person.collection.find(['vehicleNumber': ['$regex':'.*GJ18AD.*'] ]).sort(['datetime':-1])

It's works for me in the MongoDB version 4.2.1.它在 MongoDB 4.2.1 版中对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM