I am using the MongoDB-Csharp driver and I was wondering what the proper way to insert and query date field?
I tried using storing the dates using System.DateTime, but I am having issues when I try to query by date.
example:
Inserting Data
var mongo = new Mongo();
var db = mongo.GetDatabase(dbName);
var collection = db.GetCollection(collectionName);
var document = new Document();
document["date"] = DateTime.Now.ToUniversalTime();
collection.Save(document);
Querying Data
var mongo = new Mongo();
var db = mongo.GetDatabase(dbName);
var collection = db.GetCollection(collectionName);
var results = collection.Find(
new Document()
{
{
"date",
new Document()
{
{
"$lte", DateTime.Now.ToUniversalTime()
}
}
}
}
);