I just started working on MongoDB. From my JavaScript client I am sending a JSON string to ASP.NET WEB API project. Is it possible to use this JSON string directly and save it into MongoDB? I also want to know whether this approach make sense ?
I am thinking of passing the JSON
from client and on the server side read the string
as
[System.Web.Mvc.HttpPost]
public dynamic SaveData([FromBody] string data)
{
System.Web.HttpContext.Current.Request.Form[0]
return null;
}
Converting a BSON Object to a JSON StringUse the asString method to convert the BSON document to an extended JSON string. See http://docs.mongodb.org/manual/reference/mongodb-extended-json/ for more information on extended JSON.
Unlike systems that store JSON as string-encoded values, or binary-encoded blobs, MongoDB uses BSON to offer powerful indexing and querying features on top of the web's most popular data format.
BSON is a binary serialization format. " BSON" stands for "Binary JSON", but BSON and JSON are serialized very differently. BSON is "JSON-like", because objects are represented as name-value pairs, similar to JSON. Unlike JSON, numeric data types are stored as bytes, not strings.
Try this:
string json = "...";
BsonDocument.Parse(json);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With