1

I have a MongoDB server which have 1GB memory.

I have only one collection in the DB and it has almost 1300000 records and its size in disk is almost 1GB.

Now while I am running a query which returns one record like below:

db.collection.find({"customer.name":"Scott"})

Now there is a record for customer name = Scott. So this is working fine and returning record with few milliseconds.

Now if I run the same query with some other name which is not present in the collection, the Server is getting stopped.

I guess (I can be wrong though) this is because memory issue, DB is trying to search the whole collection and all the records are getting stored in memory and its getting crashed.

So My Question is: What is the actual problem and how to solve it?

*I don't want to increase the server memory.

*I use same volume data in another Mysql server which have only 500mb memory and it works perfect.

*I am running the Queries from direct commend line. Server has Ubuntu 14.4 OS

Arijit
  • 1,633
  • 2
  • 21
  • 35
  • Maybe it takes so much memory to check with the whole data in the collections and hence the server goes down - instead you can use $exists or count of records to first check if the document exits and if yes you can query for its data - refer https://docs.mongodb.com/manual/reference/operator/query/exists/ for exists check – Patrick Sep 19 '16 at 21:41
  • Thanks. $exists will not help me. Because it does to search for value. First checking count is good option. But When I ran the count query db.collection.find({"customer.name":"abc"}).count() its again stopped. – Arijit Sep 19 '16 at 21:57
  • but hopefully count should help you :) – Patrick Sep 19 '16 at 21:59
  • No count is not working. even count query is stopping the DB server – Arijit Sep 19 '16 at 22:00
  • Please check if this is helpful http://stackoverflow.com/questions/19559405/mongodb-querying-performance-for-over-5-million-records – Patrick Sep 19 '16 at 22:26
  • What MongoDB version are you running? Also, do you have any index defined in the collection? – kevinadi Sep 19 '16 at 23:00
  • Also, an example document would be helpful to determine if you have the correct indexes defined. – kevinadi Sep 20 '16 at 02:19
  • I think Indexing is not a problem because I do not have a Index for now. I fixed the issue by adding some swap memory in the server. Though I don't know this is the best solution or not. Thanks a lot for all your suggestions guys. – Arijit Sep 20 '16 at 20:53

0 Answers0