I am using MongoDB as the database for my web application. I am looking for a way to insert and extract dynamic JSON data without creating typed classes for it.
My web application is sending a JSON string. Then, in the backend, I convert this JSON string to BsonDocumentand paste it into MongoDB:
var obj = BsonDocument.Parse(json.ToString());
Db.GetCollection<dynamic>("Items").InsertOneAsync(obj);
This works fine except that the structure in MongoDB looks like this:
_id = ObjectId("55618d35d747199c0a486fe0")
_t = MongoDB.Bson.BsonDocument, MongoDB.Bson
_v = (3 fields)
username = "JohDoe"
password = "xxxxx"
email = "em@il.com"
In other words, my JSON object is stored internally _v. I do not want to store everything in the "sub" property. I want it to look like this:
_id = ObjectId("55618d35d747199c0a486fe0")
_t = MongoDB.Bson.BsonDocument, MongoDB.Bson
username = "JohDoe"
password = "xxxxx"
email = "em@il.com"
Is it possible to store such data without creating any typed objects?
source
share