how to change type from "string" to "ObjectId" in C#

2,126 views
Skip to first unread message

new player

unread,
Feb 28, 2011, 8:27:18 PM2/28/11
to mongodb-user
excuse me.i want to use "_id" , but i don't know how to change the
type from "string" to "ObjectId" in C#.

thank you.

Code:
var query = new QueryDocument("_id", ? );

Robert Stam

unread,
Feb 28, 2011, 8:57:57 PM2/28/11
to mongodb-user
You can use ObjectId.Parse. For example:

var s = "4d6c5246e447ad3bb4495c17";
var query1 = new QueryDocument("_id", ObjectId.Parse(s));
var query2 = Query.EQ("_id", ObjectId.Parse(s));

I've also illustrated the Query builder in case you prefer to use it
instead of building the QueryDocument by hand.

new player

unread,
Feb 28, 2011, 9:14:23 PM2/28/11
to mongodb-user
it's work! thanks!!!
Reply all
Reply to author
Forward
0 new messages