I created a simple object with getters and setters:
public class MemberCanonical : IMemberCanonical { public ObjectId Id { get; set; } public String username { get; set; } public String email { get; set; } public String status { get; set; } public IEnumerable<string> roles { get; set; } }
Now I want to insert a new item into the database with:
try { memberObj.username = username; memberObj.email = email; memberObj.status = "active"; // memberObj.Id = new ObjectId().ToString(); this.membershipcollection.Insert(memberObj, SafeMode.True); return true; } catch(Exception ex) { return false; }
I would expect the insert to create a unique _id (Id), but that will not happen. After pasting, when I look at the _id field, I get "0000000 ...."
What do I need to do so that Mongo can generate its own _id on insertion?
c # mongodb mongodb-.net-driver
goldfinger
source share