mongodb死于正则表达式搜索

时间:2013-11-26 11:45:52

标签: regex mongodb

简单的正则表达式搜索:

> db.lipsum.find({"d.text":{$regex:'cursus'}});

做得很好,并且返回了数千。

有点复杂:

db.lipsum.find({"d.text":{$regex:'cursus((?!turpis massa).)*$'}});

杀死了mongod:

Tue Nov 26 11:01:03 DBClientCursor::init call() failed
Tue Nov 26 11:01:03 query failed : lipsum.lipsum { d.text: { $regex: "cursus((?!turpis massa).)*$" } } to: 127.0.0.1:27017
Error: error doing query: failed
Tue Nov 26 11:01:03 trying reconnect to 127.0.0.1:27017
Tue Nov 26 11:01:03 reconnect 127.0.0.1:27017 failed couldn't connect to server 127.0.0.1:27017

mongodb.log中没有任何内容。最后一行是:

Tue Nov 26 11:00:17 [conn2] query lipsum.lipsum query: { d.text: { $regex: "cursus" } } cursorid:5200338523215960499 ntoreturn:0 keyUpdates:0 locks(micros) r:1266 nreturned:101 reslen:159838 1ms
Tue Nov 26 11:00:18 [conn2] run command admin.$cmd { replSetGetStatus: 1.0, forShell: 1.0 }
Tue Nov 26 11:00:18 [conn2] command admin.$cmd command: { replSetGetStatus: 1.0, forShell: 1.0 } ntoreturn:1 keyUpdates:0  reslen:76 0ms

所以有两个问题:

  1. 如何获取详细信息发生了什么?
  2. 如何在“cursus”之后编写正确的正则表达式来获取没有“turpis massa”的对象?

  3. Mongodb 2.2.4,Ubuntu 13.04。

    我的测试数据库:

    load("lorem.js"); // from https://github.com/f/loremjs
    
    var lorem = new Lorem;
    lorem.type = Lorem.TEXT;
    lorem.query = '2p';
    
    for(var i=0; i < 20000; i++){
        db.lipsum.insert({t: $currentDate, d: {text:lorem.createLorem()}})
    }
    

0 个答案:

没有答案