mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-20 02:29:39 +08:00
Add Mongo DB
This commit is contained in:
@@ -11,18 +11,35 @@ namespace MongoDbTest
|
||||
{
|
||||
public class AdoTest
|
||||
{
|
||||
public static void Init()
|
||||
public static void Init()
|
||||
{
|
||||
MongoClientTest();
|
||||
MongoDbConnectionTest();
|
||||
}
|
||||
|
||||
private static void MongoDbConnectionTest()
|
||||
{
|
||||
var db= new MongoDbConnection(DbHelper.SqlSugarConnectionString);
|
||||
|
||||
var database= db.GetDatabase();
|
||||
var collections = database.GetCollection<BsonDocument>("b");
|
||||
// 插入一个文档,MongoDB 会创建数据库和集合
|
||||
var document = new BsonDocument { { "name", "bbbbbb" }, { "age", 30 } };
|
||||
collections.InsertOne(document);
|
||||
var list = collections.AsQueryable<BsonDocument>().ToList();
|
||||
}
|
||||
|
||||
private static void MongoClientTest()
|
||||
{
|
||||
//开发中
|
||||
var client = new MongoClient("");
|
||||
var database = client.GetDatabase("test");
|
||||
var client = new MongoClient(DbHelper.ConnectionString);
|
||||
var database = client.GetDatabase("SqlSugarDb");
|
||||
// 获取当前数据库中的所有集合
|
||||
var collections = database.ListCollections();
|
||||
|
||||
|
||||
MongoDbConnection connection = new MongoDbConnection("");
|
||||
connection.Open();
|
||||
connection.Close();
|
||||
var collections = database.GetCollection<BsonDocument>("a");
|
||||
// 插入一个文档,MongoDB 会创建数据库和集合
|
||||
var document = new BsonDocument { { "name", "aaaa" }, { "age", 30 } };
|
||||
collections.InsertOne(document);
|
||||
var list = collections.AsQueryable<BsonDocument>().ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user