Possible Duplicate:
How to set primary key in mongodb?
As I understood _id is generated by mongodb. Is there any way to set it manually? And if so, how to do it using C# driver?
Possible Duplicate:
How to set primary key in mongodb?
As I understood _id is generated by mongodb. Is there any way to set it manually? And if so, how to do it using C# driver?
I managed to find answer by myself. For C# driver it is enough to give the name Id
or _id
to desired property, and not to have ObjectId
type property in your class. Then inside driver somehow decide that this property is _id
for your data in mongodb.
Yes, you can generate an ObjectID at the client side. Every client library should provide a way to that. Here's how it is in ruby driver
require 'mongo'
oid = BSON::ObjectId.new
But the _id
field doesn't have to be an ObjectId. It can be anything (except for array). You can provide your own value when inserting the document and mongo will happily accept it.