MongoDB id remains null after InsertOneAsync -


i have base class entity has string id member , derived class a.

but when creating new instance of derived class , using insertoneasync add collection, document added database null id value.

using objectid id seem work, i'm trying prevent mongodb dependency in models.

i experimented following code, results same:

bsonclassmap.registerclassmap<entity>(cm => {     cm.mapidfield(x => x.id).setserializer(new stringserializer(bsontype.objectid)); }); 

i had same issue , got work (with 2.0 driver) these attributes:

[bsonid] [bsonrepresentation(bsontype.objectid)] [bsonignoreifdefault] 

or equivalent bsonclassmap fluent interface:

bsonclassmap.registerclassmap<entity>(cm => {       cm.mapidfield(x => x.id)       .setserializer(new stringserializer(bsontype.objectid))       .setignoreifdefault(true); }); 

i tried same working .replaceoneasync upsert on leaves id still null


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -