Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using MongoDB.Bson;
- using MongoDB.Bson.IO;
- using MongoDB.Bson.Serialization;
- using MongoDB.Bson.Serialization.Attributes;
- using MongoDB.Driver;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace M101DotNet
- {
- class Program
- {
- static void Main(string[] args)
- {
- MainAsync(args).GetAwaiter().GetResult();
- Console.WriteLine("Press enter");
- Console.ReadLine();
- }
- static async Task MainAsync(string[] args)
- {
- var client = new MongoClient();
- var db = client.GetDatabase("Phucdb");
- var col = db.GetCollection<BsonDocument>("widgets");
- // Drop r Insert
- await db.DropCollectionAsync("widgets");
- var docs = Enumerable.Range(0, 10).Select(i => new BsonDocument("_id", i).Add("x", i));
- await col.InsertManyAsync(docs);
- //Update
- var result = await col.ReplaceOneAsync(
- new BsonDocument("_id", 5),
- new BsonDocument("x", 30));
- // Xuat
- await col.Find(new BsonDocument()).ForEachAsync(x => Console.WriteLine(x));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement