L
L
Lihonosov2012-05-27 17:51:25
MongoDB
Lihonosov, 2012-05-27 17:51:25

Mongodb - multi-criteria search

We need advice from those who worked with MongoDB:
Let's say we have data like this:

{
  a: {
    id:1,
    id2:3
  },	
  b: [ "str1", "str2", "str3" ],
  c: [ 
    {f:"UA", g:12, s:"some string"},
    {f:"RU", g:1, s:"some string2"}
   ],
  d: [ 
    {f:"UA", g:2, s:"some string3"},
    {f:"UA", g:2, s:"some string4"}
   ],
  dtF: ISODate("2012-04-25T21:00:00Z"),
  dtT: ISODate("2012-04-28T21:00:00Z"),
  cc: true,
  m: 0,
  v: 32,
  ...
}


There are about 3M records in the collection.

It is necessary to search this collection in different fields, i.e. in one request, all fields can participate in another, only a few.

Request examples:

{ "c.f" : "UA" , "d.f" : "UA" , "c.s":{"$regex":"some", "$options" : ""}} 


{ "c.f" : "UA" , "d.f" : "UA" , "c.g" : { "$in" : [ 17]}, "b":{"$nin":["str1"]} 


{ "m" : { "$gte" : 2 , "$lte" : 7} , "v" : { "$lte" : 50} , "c.f" : "UA" , "d.f" : "UA" , "c.g" : { "$in" : [ 27]}}


{"m" : { "$lte":20} , "v" : { "$lte" : 8},"c.f":"UA","c.g":{"$in":[1,12,16]}, "c.s":{"$regex":"some", "$options" : ""},"d.f":"RU","d.g":{"$in":[25,16]}, "d.s":{"$regex":"some2", "$options" : ""},cc:false, "$or" : [ { "dtF" : { "$gte" : { "$date" : "2012-05-06T21:00:00.000Z"}} , "dtT" :  null } , { "dtF" : { "$gte" : { "$date" : "2012-05-06T21:00:00.000Z"}} , "dtT" : { "$lte" : { "$date" : "2012-06-06T21:00:00.000Z"}}}], "b":{"$in":["str1"]}}


Problems that I see
: There can be many different query options
- You cannot create a composite index that includes several "array fields"
- The more indexes, the lower the write speed.

What do you advise? Is MongoDB up to the task?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
maratfmu, 2012-05-27
@maratfmu

I advise you to take a sample of the fields of the most popular requests and, based on these fields, build your own index for each request. Solve the performance problem by 80%

G
gvsmirnov, 2012-05-27
@gvsmirnov

MongoDB is, of course, cool, web scale and all, but you seem to be solving the problem of parametric search. There are specially designed tools for just this task. Lucy, for example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question