I'm trying to inserting data to MongoDB using C#, JObject, and BSONDocument without defining any model (direct JSON). Maybe this is possible duplicate from How to remove _v and _t from mongo document and How to prevent _t and _v when inserting into MongoDB? , but I can't find my answer.
But there's _t and _v field. And the value that i put before, stored in _v field as an object.
Here's the code
var mongo = new MongoClient(new MongoUrl("mongodb://localhost"));
var db = "test";
var database = mongo.GetDatabase(db);
dynamic obj = new JObject();
obj["coy"] = "haha";
BsonDocument c = BsonDocument.Parse(obj.ToString());
database.GetCollection<dynamic>("test").InsertOne(c);
and the result
// 1
{
"_id": ObjectId("5ca5ace48d93c485ce90bb43"),
"_t": "MongoDB.Bson.BsonDocument, MongoDB.Bson",
"_v": {
"coy": "haha"
}
}
Any ideas? Thank you.