【发布时间】:2017-06-16 17:12:18
【问题描述】:
我有一个复杂的嵌套动态 BsonDocument,我需要查询该文档以找到所有具有相同“类型”的“记录”。
Json 的一个例子是:
{
"Id": "",
"CategoryId": "41",
"FormVersion": "4",
"Metadata":{
"title": "some title",
"author": "Kevin B.",
"location": {
"url": "ed5cf2ea-c920-43b2-807b-65f5e4cac650.jpeg",
"type": "upload",
"size": "1001",
"format": "application/json",
"numbers": [1,2,3,4]
},
"file": {
"url": "ed5cf2ea-c920-43b2-807b-65f5e4cacddf50.jpeg",
"type": "upload",
"size": "1001",
"format": "application/json",
"numbers": [1,2,3,4]
}
}
}
这是通过我的控制器中的自定义 ModelBinder 映射到此类:
内容
public class Content : Base
{
public Guid Id { get; set; }
public int FormVersion { get; set; }
public int CategoryId { get; set; }
public BsonDocument Metadata { get; set; }
}
正如您在上面看到的,“元数据”被映射到 BsonDocument。
现在,在将整个文档保存到 MongoDB 之前,我需要找到所有类型为“上传”的“记录”。我需要这个,因为我需要移动临时文件夹中的文件,并且这些记录具有临时文件 URI。
在示例中,location 和 file 是具有“上传”类型的对象。我需要以某种方式查询此 bsondocument 并仅获取这些文档,移动文件并保存。
我尝试使用 linq,但没有成功。我已经查看了this,但我没有可以使用的集合。它只是一个对象。
【问题讨论】: