I am new to MongoDB and I am interested in developing with it in the .Net environment.
I have a question after completing the .Net Developers course.
During the course there was a lot of times when the New BsonDocument keyword was used… While I understand that the use of this keyword instantiates the BsonDocument class, I am confused as to the amount of times it is used. Consider the below example:
private BsonElement BuildRuntimeBucketStage()
{
return new BsonElement("runtime", new BsonArray
{
new BsonDocument("$bucket",
new BsonDocument
{
{"groupBy", "$runtime"},
{
"boundaries", _runtimeBoundaries
},
{"default", "other"},
{
"output",
new BsonDocument("count",
new BsonDocument("$sum", 1))
}
})
});
}
Why are you calling the new BsonDocument 4 times? In my programming experience, (Which is limited) I was led to believe that so long as you can access the instance in which you instantiated the class, there was no need to re instantiate it.
What am I missing here?
I am trying to learn when I need to call a new document and there is VERY limited documentation on this. Is there a reference that I can read? If so, can someone provide a link so I can read it. If it is just the mongo driver, that doesn’t really explain to me why there is a need to call a new instance so many times.
Is this the same as the $AddFields: keyword?