1

We are using MongoDB for our storage. We have a collection like the folowing.

collection{
{
    "_id" : ObjectId("....."),
    "dataCriacao" : ISODate("..."),
    "ativo" : true,
    "title" : "tile",
    "text" : "text",
    "badge" : 0,
    "pedidoId" : null,
    "userID" : null,
    "createdByAdmin" : true
}
{
    "_id" : ObjectId("..."),
    "dataCriacao" : ISODate("..."),
    "ativo" : true,
    "title" : null,
    "text" : null,
    "badge" : 0,
    "pedidoId" : "2",
    "userID" : "6098821",
    "createdByAdmin" : false
}}

The collection is expected to get quite big and i will often query it depending on createdByAdmin. In this situation is it worth it to add an index on this field? My boss told me to but everything I found online is against indexes on boolean fields.

Community
  • 1
  • 1
Juraj Petrik
  • 895
  • 1
  • 10
  • 25
  • 1
    Please state where you found that information and what arguments were presented there. – Philipp Mar 21 '14 at 18:15
  • I was mostly going by this post, though it doesn't differentiate between SQl and noSQL http://stackoverflow.com/a/1130/3362717 – Juraj Petrik Mar 21 '14 at 18:29
  • You might consider there are 3 states: true, false, and unset. Indexing the field, with sparse, could make good sense. http://stackoverflow.com/questions/11121403/should-i-use-sparse-index-for-boolean-flags-in-mongodb – WiredPrairie Mar 21 '14 at 19:40
  • 1
    Can you share an example of a standard query as well? You will want to create queries that can be as selective as possible in which documents it has to look at. Your indexes should then be built to support. More on selectivity here: http://docs.mongodb.org/manual/tutorial/create-queries-that-ensure-selectivity/ – James Wahlin Mar 21 '14 at 19:48
  • my queries are just findAll where createdByAdmin==false, and findAll where createdByAdmin==true. the way my program runs createdByAdmin will never be unset, just true/false – Juraj Petrik Mar 21 '14 at 22:19

0 Answers0