|
It is often useful to represent a BSON document as a JSON string, if for no other reason than it is usually easier to construct a string value representing a complex document than to directly construct the BsonDocument itself.
However, if the document is not a constant, then we need some way to inject values into it.
For example, rather than:
var name = "John";
|
var age = 11;
|
var document = Json.Parse(string.Format("{{ name : \"{0}\", age: {1} }}", name, age));
|
It would be much nicer to write:
var document = Json.Parse("{ name : #, age : # }", name, age);
|
Or something similar to that (the exact syntax needs to be determined).
Not only would this be much friendlier than formatting up strings with values inside it, it would also avoid all sorts of dangers that might crop up if the values inserted into the formatted string aren't properly formatted or escaped.
|