net官方驱动操作MongoDB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MongoDB.Bson;
using MongoDB.Driver;

namespace WebApplication1
{
    public partial class index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // 使用连接字符串连接
            var client = new MongoClient("mongodb://localhost:27017");

            var database = client.GetDatabase("test");

            var collection = database.GetCollection("lml");

            var document = collection.Find(new BsonDocument()).FirstOrDefault();

            this.TextBox1.Text = document.ToString();
            //Console.WriteLine(document.ToString());
        }
    }
}

你可能感兴趣的:(net官方驱动操作MongoDB)