Problem on object inserting

439 views
Skip to first unread message

Catsy

unread,
Jun 12, 2012, 3:11:49 PM6/12/12
to mongodb...@googlegroups.com
Hello,
I have the following object:
    public class MyObject
    {
        public ObjectIdentifier Id { get; set; }

        [BsonElement("locId")]
        public int LocationId { get; set; }
    }

and trying to insert the new value. I thought that id should be generated on the MongoDB server side so I didn't touch the Id field and just try to save it into database:

Database.MyObjects.Save(MyObject);

But it throws the exception "No IdGenerator found."

What to do with it???

Thanks

Robert Stam

unread,
Jun 12, 2012, 3:13:45 PM6/12/12
to mongodb...@googlegroups.com
What is the data type ObjectIdentifier? A class of yours?

The driver and server know how to generated ObjectIds, but not instances of your own data types.

You could register an IdGenerator for your data type if you can't use the standard ObjectId for your Ids.

Catsy

unread,
Jun 12, 2012, 3:23:32 PM6/12/12
to mongodb...@googlegroups.com
Oh, you are right! i just mixed the MongoDB ObjectId type and our own ObjectIdentifier type that is intended for absolutely different thing.

Thanks!
Reply all
Reply to author
Forward
0 new messages