c# - MongoDb indexes in ASP.NET MVC -


i'm working on asp.net mvc application of data stored in mongodb database.

my collection contains documents stored (c# class example):

public class metereddatareading {     [bsonid]     public int myid { get; set; }     public string ediel { get; set; }     public datetime createddate { get; set; }     public datetime startoccurence { get; set; }     public int version { get; set; }     public datetime occurence { get; set; }      [bsonrepresentation(mongodb.bson.bsontype.double)]     public decimal quantity { get; set; } } 

now, when comes indexes, i'm bit lost. fields we're using is: ediel, occurence , createddate example query (pesudo) be:

get metereddatareadings ediel = 1234 , occurence >= startdate , occurence <= enddate , createddate <= deadlinedate order occurence descending

so, first pondering have is: how make indexes. should create single-field index 3 fields (ediel, occurence , createddate)? or should have @ creating maybe compound index? , if so, fields should included in compount index? ediel , occurence?

second thing i'm bit stuck , when these indexes should created. should create them when application starts up, in application_start()? or should created once via mongodb shell , and that's it?

any help/hint/insight appreciated :-)

in case, need set compound index.


db.metereddatareading.createindex( { "ediel": 1, "occurence": 1, "createddate":1 } )

mongodb indexes important aspect of database design , application performance.

also can check whether queries doing column reads using explain(). if doing column scans need index , make sure, queries hitting index , disk reads avoided.

`db.metereddatareading.find({$query:    { "ediel": 1234,       {"occurence" :$gte: isodate("2010-04-29t00:00:00.000z"),                    $lte: isodate("2010-05-01t00:00:00.000z")},      "createddate":$lte: isodate("2010-05-01t00:00:00.000z")},      $orderby: { occurence : -1 } }).explain("executionstats")` 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -