Hi,
Here am inserting the Json data into MongoDB by passing the values from c# code, here am accessing the "test"database to insert the piece of data, Add MongoDB refference to the solution and access them in the class file.
Find the below console application code to insert the details into MongoDB
Here am inserting the Json data into MongoDB by passing the values from c# code, here am accessing the "test"database to insert the piece of data, Add MongoDB refference to the solution and access them in the class file.
Find the below console application code to insert the details into MongoDB
using System.Collections.Generic;
using MongoDB.Driver;
using MongoDB.Bson;
namespace InsDtls
{
class Program
{
static void Main(string[] args)
{
var Client = new MongoClient();
var DB = Client.GetDatabase("test");
var collection = DB.GetCollection<BsonDocument>("store");
var documnt = new BsonDocument
{
{"ProductName","Sony Earphones"},
{"Price","12.5"},
{"Made
in","US"}
};
collection.InsertOneAsync(documnt);
Console.WriteLine("Press
Enter to insert the data");
Console.ReadLine();
}
}
}