我正在以 stigify json 格式获取数据
"[{\"ApplytoAllYesNo\":\"\",\"PartNumber\":\"\",\"Description\":\"\",\"LotNumber\":\"\",\"Revision\":\"\",\"Comment\":\"\",\"QualStatus\":\"\",\"Upload\":\"\",\"buildID\":\"62161d4fee3776fba3d8b83e\"},{\"ApplytoAllYesNo\":\"\",\"PartNumber\":\"\",\"Description\":\"\",\"LotNumber\":\"\",\"Revision\":\"\",\"Comment\":\"\",\"QualStatus\":\"\",\"Upload\":\"\",\"buildID\":\"62161d4fee3776fba3d8b83e\"},{\"ApplytoAllYesNo\":\"\",\"PartNumber\":\"\",\"Description\":\"\",\"LotNumber\":\"\",\"Revision\":\"\",\"Comment\":\"\",\"QualStatus\":\"\",\"Upload\":\"\",\"buildID\":\"62161d4fee3776fba3d8b83e\"},{\"ApplytoAllYesNo\":\"\",\"PartNumber\":\"\",\"Description\":\"\",\"LotNumber\":\"\",\"Revision\":\"\",\"Comment\":\"\",\"QualStatus\":\"\",\"Upload\":\"\",\"buildID\":\"62161d4fee3776fba3d8b83e\"},{\"ApplytoAllYesNo\":\"\",\"PartNumber\":\"\",\"Description\":\"\",\"LotNumber\":\"\",\"Revision\":\"\",\"Comment\":\"\",\"QualStatus\":\"\",\"Upload\":\"\",\"buildID\":\"62161d4fee3776fba3d8b83e\"}]"
每次这些数据都会发生变化,这就是为什么我无法使用固定模型的原因,因为我的对象没有固定数量的列,并且每个请求中的列数都会发生变化,这些列是在前端创建的。
我只想将 json stigify 数据插入到 mongoDB 中,无论它来自该对象。
[HttpPost("saveBuildData")]
public async void saveBuildData(BuildSchema data)
{
await _buildsService.insertBuildConfigData(data.buildData);
}
public async Task insertBuildConfigData(dynamic obj)
{
var connectionString = _configuration["DatabaseSettings:ConnectionString"];
var client = new MongoClient(connectionString);
var database = client.GetDatabase("cascade");
var collection = database.GetCollection<BsonDocument>("buildconfig_MATERIAL");
var q = BsonSerializer.Deserialize<BsonDocument>(obj);
await collection.InsertOneAsync(q);
}
上面的代码不起作用,我无法将数据插入 mongoDB。