本文整理汇总了C#中IMongoClient.GetDatabase方法的典型用法代码示例。如果您正苦于以下问题:C# IMongoClient.GetDatabase方法的具体用法?C# IMongoClient.GetDatabase怎么用?C# IMongoClient.GetDatabase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMongoClient
的用法示例。
在下文中一共展示了IMongoClient.GetDatabase方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BookContext
public BookContext(IMongoClient mc)
{
//Connecting to local
client = mc;
this.db = client.GetDatabase("bookStore");
}
示例2: 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");
}
示例3: maplistcontent
public async Task<HttpResponseMessage> maplistcontent(string area)
{
_mongoClient = new MongoClient(ConfigurationManager.ConnectionStrings["MongoDBContext"].ConnectionString);
_mongoDatabase = _mongoClient.GetDatabase(ConfigurationManager.AppSettings["civilgisDBname"]);
//_mongoDatabase.ListCollectionsAsync
// List<BsonDocument> list = _mongoDatabase.ListCollectionsAsync().Result.ToListAsync().Result;
string result = "[";
int count = 0;
area = area + "_";
using (var cursor = await _mongoDatabase.ListCollectionsAsync())
{
while (await cursor.MoveNextAsync())
{
var batch = cursor.Current;
foreach (var bsonDocument in batch)
{
var _collection_nm = bsonDocument.GetValue("name");
string rd = _collection_nm.ToString();
if (rd.Contains(area) == true)
{
// output format: [[1,"oc_address"],[2,"oc_bounds"],[3,"oc_cities"],[4,"oc_education_facility"],[5,"oc_fire_grid"],[6,"oc_fire_stations"],[7,"oc_hospitals"],[8,"oc_hwy_majorrd"],[9,"oc_rails"],[10,"oc_streets"],[11,"oc_water"]]
count++;
result = result + '[' + Convert.ToString(count)+ ',' + '"' +rd + '"' +"],";
}//if
}
}
}// using
// remove last ","
result = result.Remove(result.Length - 1);
result = result + "]";
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, result, "text/plain");
return response;
}
示例4: GetMongoDatabase
static IMongoDatabase GetMongoDatabase(IMongoClient mongoClient)
{
var url = GetUrl();
var settings = new MongoDatabaseSettings
{
GuidRepresentation = GuidRepresentation.Standard,
WriteConcern = WriteConcern.Acknowledged
};
var mongoDatabase = mongoClient.GetDatabase(url.DatabaseName, settings);
return mongoDatabase;
}
示例5: MongoDbRepository
public MongoDbRepository(IOptions<AppSettings> appSettings)
{
_client = new MongoClient(appSettings.Value.MongoDbConnectionString);
_database = _client.GetDatabase(appSettings.Value.MongoDbName);
_tweetCollection = _database.GetCollection<Tweet>("tweets");
_userFollowsCollection = _database.GetCollection<UserFollows>("user_follows");
_userLikesCollection = _database.GetCollection<UserLikes>("user_likes");
_conversationCollection = _database.GetCollection<Conversation>("conversations");
_userNotificationCollection = _database.GetCollection<UserNotifications>("user_notifications");
}
示例6: MongoDBManager
public MongoDBManager()
{
_mongoClient = new MongoClient(ConfigurationManager.ConnectionStrings["DrustveneMrezeConnectionString"].ConnectionString);
_mongoUserInfoDatabase = _mongoClient.GetDatabase(ConfigurationManager.AppSettings["DrustveneMrezeDatabaseName"]);
_mongoMoviesDatabase = _mongoClient.GetDatabase(ConfigurationManager.AppSettings["DrustveneMrezeMoviesDatabaseName"]);
_mongoTweetsDatabase = _mongoClient.GetDatabase(ConfigurationManager.AppSettings["DrustveneMrezeTweetsDatabaseName"]);
}
示例7: 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;
}
}
示例8: DataStore
private DataStore(string databaseName, MongoDatabaseSettings settings = null)
{
_client = new MongoClient();
_database = _client.GetDatabase(databaseName, settings);
DatabaseName = databaseName;
}
示例9: DefaultController
public DefaultController() {
_client = new MongoClient(new MongoClientSettings
{
Server = new MongoServerAddress("localhost", 27017)
});
_database = _client.GetDatabase("test");
}
示例10: DocumentDb
public DocumentDb(string DBName,ISchemaContext SchemaContext)
{
_client = new MongoClient();
_database = _client.GetDatabase(DBName);
ctx = SchemaContext;
this.DBName = DBName;
}
示例11: 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");
}
示例12: 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;
}
示例13: 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;
}
}
}
示例14: 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);
}
示例15: MongoConnection
public static IMongoDatabase MongoConnection() {
client = new MongoClient("mongodb://145.24.222.117/Planetis3");
database = client.GetDatabase("Planetis3");
return database;
}