Tuesday, 18 April 2017

Mongod is crashing when querying the database

I have an AWS instance with nodejs and mongod running. The collection I am trying to query from has roughly 289248 documents in there.

Here is the code I am using to query my data:

var collection = db.collection('my_collection');
collection.find({ $and: [ 
        {"text" : {$regex : ".*"+keyword+".*"}}, 
        {"username" : username} 
    ] }).limit(10).toArray(function(err, docs) {

Now originally, I was having issues querying just a username collection.find({"username":username}) because there are so many entries in mongo. So I started limiting my code and in the mongo console, I can set a limit of 30 and it results the results I am looking for.

However, then when I run this application on nodejs, when I query this command, it crashes my mongod service and I have to restart it. On the node server, limit of 1 works fine but limit of 5 does not. I can't simply use limit of 1 if there are many more results in the database. What can I do?



via user1883614

No comments:

Post a Comment