.net, mongodb, query

Now I wanna step into mongodb query. Using mongodb driver for .Net it’s damn easy.

var q = Query.And(Query.GTE(“TglProposal”, BsonValue.Create(double.Parse(tglMasuk1))),
Query.LTE(“TglProposal”, BsonValue.Create(double.Parse(tglMasuk2)))); // tglmasuk1 >= x <= tglmasuk2
List bantuans = mongoDB.GetCollection(“Bantuan”).Find(q).ToList();

It’s used to find any data within range of date periods.
I’m feeling comfort saving date as double🙂.

Now, I wanna add more query ‘equal’ and ‘not equal’.

var queryApproved = approved ? Query.NE(“TglRealisasi1”, BsonValue.Create(0)) :
Query.EQ(“TglRealisasi1”, BsonValue.Create(0));

And add it to query date periods.

var q = Query.And(queryApproved,
Query.GTE(“TglProposalStr”, BsonValue.Create(double.Parse(tglMasuk1))),
Query.LTE(“TglProposalStr”, BsonValue.Create(double.Parse(tglMasuk2)))); // tglmasuk1 >= x <= tglmasuk2

Query MongoDB

Aside

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s