..ToBsonDocument()极慢(60ms)

时间:2019-03-04 09:40:14

标签: c# mongodb

我正在尝试将BsonElement转换为BsonDocument,所以我可以使用TryGetValue();。但这需要永远(60ms)!我迫不及待想要一百万个参赛作品。 是否有其他方法可以从BsonValue内部获取值?还是我可以以某种方式显着提高速度?

我需要的是inside2的唯一列表(结构位于结尾)

现在我要做类似的事情,从数组中获取值。

//Maybe this code right here is not working, but you get the idea
// convert to doc -> get value -> convert to doc -> get value
BsonDocument doc = ...;
BsonValue val1;
doc.TryGetValue("files", out val1);
BsonDocument fileAsDoc = val1.ToBsonDocument();
BsonValue catetgoriesValue;
fileAsDoc.TryGetValue("Categories", out catetgoriesValue);
BsonDocument catAsDoc = catetgoriesValue.ToBsonDocument();
BsonValue data3Value;
catAsDoc.TryGetValue("data3", out data3Value);
BsonDocument data3AsDoc = data3.ToBsonDocument();
foreach(BsonElement inside in data3AsDoc){
    //.....
}

这就是我的Bson的组合方式:

{
    "_id": ObjectId("1234567890123"),
    "language" : "DE",
    "files" : [
        {
          "something" : 10,
          "something2" : "something2..",
          "Categories" : [
            {
              "data1" : "1234",
              "data2" : "1234",
              "data3" : [
                {
                  "inside1" : false,
                  "inside2" : "this is what i need at the end"
                },
                {
                  "inside1" : false,
                  "inside2" : "this is what i need at the end"
                }
              ]
            },
          [....]
           {
              "data1" : "1234",
              "data2" : "1234",
              "data3" : [
                {
                  "inside1" : false,
                  "inside2" : "this is what i need at the end"
                },
                {
                  "inside1" : false,
                  "inside2" : "this is what i need at the end"
                }
              ]
            }
          ],
          "something3" : "text",
          "something4" : "text",
          "something5" : "text",
          "something6" : "text",
          "something7" : "text",

        }
    ]
}

0 个答案:

没有答案