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.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<Person>("users");
- var list = await col.Find(x => x.Name.Equals("Phuc")).ToListAsync();
- foreach (var doc in list)
- {
- Console.WriteLine(doc);
- }
- }
- private class Person
- {
- public ObjectId Id { get; set; }
- public string Name { get; set; }
- public int Age { get; set; }
- public string Profesion { get; set; }
- public override string ToString()
- {
- return string.Format("Id: {0}, Name: \"{1}\", Age: {2}, Profession: \"{3}\"", Id, Name, Age, Profesion);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement