本文整理汇总了C#中IMongoClient类的典型用法代码示例。如果您正苦于以下问题:C# IMongoClient类的具体用法?C# IMongoClient怎么用?C# IMongoClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IMongoClient类属于命名空间,在下文中一共展示了IMongoClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BookContext
public BookContext(IMongoClient mc)
{
//Connecting to local
client = mc;
this.db = client.GetDatabase("bookStore");
}
示例2: AdminService
public AdminService(IMongoClient client, IMongoDatabase db, StoreSettings settings)
{
_client = client;
_db = db;
_settings = settings;
_clientSerializer = new ClientSerializer();
}
示例3: GetActiveDatabases
static List<string> GetActiveDatabases(IMongoClient client)
{
List<string> dbs = new List<string>();
using (var cursor = client.ListDatabases()) // await + Async() seem to exit the programm ... @@@ ask Piercesare why
{
cursor.ForEachAsync(d => dbs.Add(d.GetElement("name").Value.AsString)); //use await?
}
return dbs;
}
示例4: DistrictsRepository
public DistrictsRepository(IMongoClient client, string database)
{
// todo: move this out to IOC config
var cp = new ConventionPack();
cp.Add(new CamelCaseElementNameConvention());
ConventionRegistry.Register("camel case", cp, x => true);
_client = client;
_db = _client.GetDatabase(database);
_collection = _db.GetCollection<District>("districts");
}
示例5: Disconnect
public static void Disconnect()
{
if (_mongoClient != null)
{
_mongoClient = null;
}
Databases = null;
}
示例6: Main
public static void Main(string[] args)
{
// #Connect to Db Shop => caseSensitive!!!
client = new MongoClient("mongodb://127.0.0.1");
database = client.GetDatabase("Shop");
//var eDrink = new EnergyDrink("Hell", 1.05);
// #connect to table EnergyDrinks
var drinksCollection = database.GetCollection<EnergyDrink>("EnergyDrinks");
while (true)
{
Console.Clear();
Console.WriteLine("Enter command:");
Console.WriteLine("Add new drink: => 1");
Console.WriteLine("Get all drinks: => 2");
Console.WriteLine("Get drinks by name => 3");
Console.WriteLine("Get drinks by price => 4");
var command = Console.ReadLine();
switch (command)
{
case "1": InsertToDatabase(drinksCollection); break;
case "2": GetAllDrinks(drinksCollection); break;
case "3": SearchByName(drinksCollection); break;
case "4": SearchByPrice(drinksCollection); break;
default:
break;
}
}
}
示例7: DatabaseContext
static DatabaseContext()
{
//var connectionString = ConfigurationManager.ConnectionStrings[CONNECTION_STRING_NAME].ConnectionString;
var connectionString = "mongodb://dbadmin:[email protected]:55722/edubase";
_client = new MongoClient(connectionString);
_database = _client.GetDatabase(DATABASE_NAME);
}
示例8: InsertMongoDb
public static void InsertMongoDb()
{
try
{
_client = new MongoClient();
_database = _client.GetDatabase("test");
var document = new BsonDocument
{
{
"Utilisateur", new BsonDocument
{
{"id", "1"},
{"nom", "LAMGHARI"},
{"prenom", "Mohammed"},
{"mail", "mail"},
{"pseudo", "dskat747"},
{"mdp", "1234"},
{"handicap", "false"},
{
"ProfileParking", new BsonDocument
{
{"id", "2"},
{"profil", "admin"}
}
},
{"Reservation", new BsonDocument
{
{"id", "15"},
{"Place", new BsonDocument
{
{"id", "1"},
{"profile", "admin"},
{"mac_address", "DF,15,21,DF,00"},
{"nom", "place 01"},
{"Parking", new BsonDocument
{
{"adresse", "Valenciennes"},
{"NbPlace", "150"},
{"etat", "Operationnel"}
}
}
}
}
}
}
}
}
};
var collection = _database.GetCollection<BsonDocument>("test");
//collection.InsertOne(document);
}
catch (Exception)
{
throw;
}
}
示例9: DataStore
private DataStore(string databaseName, MongoDatabaseSettings settings = null)
{
_client = new MongoClient();
_database = _client.GetDatabase(databaseName, settings);
DatabaseName = databaseName;
}
示例10: DefaultController
public DefaultController() {
_client = new MongoClient(new MongoClientSettings
{
Server = new MongoServerAddress("localhost", 27017)
});
_database = _client.GetDatabase("test");
}
示例11: DocumentDb
public DocumentDb(string DBName,ISchemaContext SchemaContext)
{
_client = new MongoClient();
_database = _client.GetDatabase(DBName);
ctx = SchemaContext;
this.DBName = DBName;
}
示例12: GameRepository
public GameRepository()
{
string connection = System.Configuration.ConfigurationManager.ConnectionStrings["Mongodb"].ConnectionString;
_client = new MongoClient(connection);
_database = _client.GetDatabase(System.Configuration.ConfigurationManager.AppSettings["DataBaseName"]);
_collection = _database.GetCollection<GameEntity>("games");
}
示例13: getMongoDB
public static IMongoDatabase getMongoDB()
{
_client = new MongoClient("mongodb://145.24.222.168/CityGis"); //Connection string gaat hier
//_client = new MongoClient("mongodb://localhost/CityGis");
_database = _client.GetDatabase("CityGis");
return _database;
}
示例14: MongoConfig
public MongoConfig()
{
_client = new MongoClient(ConfigurationManager.AppSettings["eTimeSheetsConnectionString"]);
Database = _client.GetDatabase(ConfigurationManager.AppSettings["eTimeSheetsDBName"]);
}
示例15: MongoRepository
public MongoRepository()
{
var connectionstring = "mongodb://localhost:27017";
_client = new MongoClient(connectionstring);
_database = _client.GetDatabase("test");
_collection = _database.GetCollection<BsonDocument>("restaurants");
}