Required to write an API which should accept a request body with any structure to convert to BsonDocument and save it. Something similar as below but not seems working with Object type.
[HttpPost("InsertBsonUserWithInput")]
public async Task<ActionResult<Object>> InsertBsonUserWithInputObject(Object requestModel)
{
var dbClient = new MongoClient("mongodb://127.0.0.1:27017");
IMongoDatabase db = dbClient.GetDatabase("Identity");
var users = db.GetCollection<BsonDocument>("Users");
users.InsertOne(requestModel.ToBsonDocument());
return new OkObjectResult(requestModel);
}
While trying so, the request object always comes as string or value type and unable to convert properly to BsonDocument. At the end any structure data will be able to receive by API and that required to convert to BsonDocument.