Using MongoDB C# driver (http://github.com/samus/mongodb-csharp), seems that I’m unable to get the data by ObjectId. Below the command that I’m using:
var spec = new Document { { "_id", id } };
var doc = mc.FindOne(spec);
I also tried this:
var spec = new Document { { "_id", "ObjectId(\"" + id + "\")" } };
var doc = mc.FindOne(spec);
Both return nothing. Meanwhile, if I query it from the mongo console, it returns the expected result.
My question is, does that driver actually support the lookup by ObjectId?
Thanks..
It does support fetching by object ID. Your id variable should be an Oid. Is it the correct type?
Here is a complete program that will