Code for MongoDb With C#
-using System;
using System.Xml.Linq;
using MongoDB.Bson;
using MongoDB.Driver;
namespace WikiExampleConsole
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Connect...");
MongoSever mongo = MongoServer.Create();
mongo.Connect();
Console.WriteLine("Connected");
Console.WriteLine();
var db = mongo.GetDatabase("tutorial");
using (mongo.RequestStart(db))
{
var collection = db.GetCollection<BsonDocument>("books");
BsonDocument book = new BsonDocument()
.Add("_id", BsonValue.Create(BsonType.ObjectId))
.Add("author", "Ernest Hemingway")
.Add("title", "For Whom the Bell Tolls");
collection.Insert(book);
var query = new QueryDocument("author", "Ernest Hemingway");
foreach (BsonDocument item in collection.Find(query))
{
BsonElement author = item.GetElement("author");
BsonElement title = item.GetElement("title");
Console.WriteLine("Author: {0}, Title: {1}", author.Value, title.Value);
´
foreach (BsonElement element in item.Elements)
{
Console.WriteLine("Name: {0}, Value: {1}", element.Name, element.Value);
}
}
}
Console.WriteLine();
Console.Read();
mongo.Disconnect();
}
}
}
mongo c# driver update | ||
mongo c# elemmatch | ||
mongo c# ensureindex | ||
mongo c# eq | ||
mongo c# exists | ||
mongo c# explain | ||
mongo c# find | ||
mongo c# find all | ||
mongo c# find by id | ||
mongo c# find example | ||
mongo c# findas | ||
mongo c# findone | ||
mongo c# findoneandupdate | ||
mongo c# get all | ||
mongo c# getcollection | ||
mongo c# github | ||
mongo c# gridfs | ||
mongo c# group | ||
mongo c# hint | ||
mongo c# id |
No comments:
Post a Comment