0

Im trying to convert a BsonElement to BsonDocument, so i can use TryGetValue();. But that takes for ever (60ms)! I can't wait that for 1 Million entries. Is there an alternative to get Values from inside a BsonValue? Or can i make it somehow significantly faster?

all i need is a unique list of inside2 (Structure is at the end)

Now i do something like that, to get Values from Array.

//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){
    //.....
}

this how my Bson is put together:

{
    "_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 Answers0