MongoDB C# Driver Unable to Find by Object ID?

Posted by Hery on Stack Overflow See other posts from Stack Overflow or by Hery
Published on 2010-03-16T10:22:11Z Indexed on 2010/03/16 10:26 UTC
Read the original article Hit count: 349

Filed under:
|
|

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..

© Stack Overflow or respective owner

Related posts about mongodb

Related posts about c#