本文整理汇总了C#中MongoDatabase.GetCollection方法的典型用法代码示例。如果您正苦于以下问题:C# MongoDatabase.GetCollection方法的具体用法?C# MongoDatabase.GetCollection怎么用?C# MongoDatabase.GetCollection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDatabase
的用法示例。
在下文中一共展示了MongoDatabase.GetCollection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test2
public static void Test2(MongoDatabase db)
{
var d = new Dictionary<string, object>();
var pp = new PortalPage { Title = "This is my test", Id = "test1" };
var pc = new PortalPageColumn();
pp.Columns.Add(pc);
pc.Config["width"] = 200;
d["open"] = "open listener";
d["close"] = "close listener";
d["interval"] = 500;
pc.Config["listeners"] = d;
d = new Dictionary<string, object>();
d["open"] = "open listener";
d["close"] = "close listener";
d["interval"] = 500;
pc.Config["listeners"] = d;
var pt = new Portlet { Title = "test portlet 1", PortletClass = "GraphImage" };
pt.Config["width"] = 200;
pt.Config["height"] = 300;
pt.Config["listeners"] = d;
pc.Portlets.Add(pt);
db.GetCollection<PortalPage>().Save(pp);
var pp2 = db.GetCollection<PortalPage>().FindOneById(pp.Id);
Console.WriteLine("p2: {0}", pp2.Title);
}
示例2: ElectionsModule
public ElectionsModule()
: base("/elections")
{
//setup Mongo
m_mongoDataBase = MongoServer
.Create(ConfigurationManager.ConnectionStrings["mongoDbConnectionString"].ConnectionString)
.GetDatabase("wf1_read_model", SafeMode.False);
//configure routes
//return all elections
Get["/"] = parameters => m_mongoDataBase.GetCollection<ElectionDto>("Elections");
//return specific election
Get["/{electionid}"] = parameters =>
{
//todo: content negotiation.
var electionCollection = m_mongoDataBase.GetCollection<ElectionDto>("Elections");
string electionId = parameters.electionid;
var query = Query<ElectionDto>.EQ(election => election.Id, electionId);
return electionCollection.Find(query).FirstOrDefault();
};
//return all elections for a participant
Get["/forparticipant/{participantid}"] = parameters =>
{
var electionCollection = m_mongoDataBase.GetCollection<ElectionDto>("Elections");
string participantId = parameters.participantid;
var query = Query<ElectionDto>.EQ(election => election.ParticipantId, participantId);
return electionCollection.Find(query).ToList();
};
}
示例3: MongoGridFS
/// <summary>
/// Initializes a new instance of the MongoGridFS class.
/// </summary>
/// <param name="database">The database containing the GridFS collections.</param>
/// <param name="settings">The GridFS settings.</param>
public MongoGridFS(MongoDatabase database, MongoGridFSSettings settings)
{
_database = database;
_settings = settings.FrozenCopy();
_chunks = database.GetCollection(settings.ChunksCollectionName);
_files = database.GetCollection(settings.FilesCollectionName);
}
示例4: Start
public bool Start()
{
try
{
// Boot up DB
mongoProcess = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = Properties.Resources.mongodb_exe,
Arguments = "--journal --dbpath " + Properties.Resources.db_path,
UseShellExecute = false,
RedirectStandardOutput = false,
CreateNoWindow = true
}
};
mongoProcess.Start();
}
catch (Exception)
{
// Getting an Exception here commonly means mongod is already up and running
}
mongo = new MongoClient(); // connect to localhost
db = mongo.GetServer().GetDatabase(Properties.Resources.db_name);
drawings = db.GetCollection<Drawing.Drawing>("drawings");
highscores = db.GetCollection<Highscores.Highscore>("highscores");
items = db.GetCollection<BsonDocument>("items");
return true;
}
示例5: MongoDbRepositoryLinq
public MongoDbRepositoryLinq()
{
string connectionString = ConfigurationManager.ConnectionStrings[ConnectionStringName].ConnectionString;
MongoClient client = new MongoClient(connectionString);
server = client.GetServer();
database = server.GetDatabase(DatabaseName);
notes = database.GetCollection<NoteWithCategories>(CollectionName);
categories = database.GetCollection<Category>(CollectionNameCategories);
}
示例6: WikiMongoRepository
public WikiMongoRepository()
{
var mongoClient = new MongoClient("mongodb://wikiAdmin:asdFFF99##@localhost:23750/wiki");
var mongoServer = mongoClient.GetServer();
db = mongoServer.GetDatabase("wiki");
pages = db.GetCollection<WikiPage>("pages");
tags = db.GetCollection<WikiTag>("tags");
users = db.GetCollection<WikiUser>("users");
}
示例7: DrugLord
public DrugLord()
{
database = MongoDatabase.Create(ConfigurationManager.AppSettings["mongo"]);
money = database.GetCollection("money");
money.EnsureIndex(IndexKeys.Ascending("userToken", "secretCode"), IndexOptions.SetUnique(true));
drugs = database.GetCollection("drugs");
drugs.EnsureIndex(IndexKeys.Ascending("userToken", "secretCode"), IndexOptions.SetUnique(true));
}
示例8: FormMain
public FormMain()
{
InitializeComponent();
//var urlTo = MongoUrl.Create("mongodb://mongodb-endorphin.cloudapp.net:27017");
var urlTo = MongoUrl.Create("mongodb://localhost:27017");
var settingsTo = urlTo.ToServerSettings();
_server = MongoServer.Create(settingsTo);
_databaseCrawler = _server.GetDatabase("SyutkinCrawler");
_pages = _databaseCrawler.GetCollection("Pages");
_posts = _databaseCrawler.GetCollection("Posts");
}
示例9: BeforeEachTest
public void BeforeEachTest()
{
var client = new MongoClient("mongodb://localhost:27017");
Database = client.GetServer().GetDatabase("identity-testing");
Users = Database.GetCollection<IdentityUser>("users");
Roles = Database.GetCollection<IdentityRole>("roles");
IdentityContext = new IdentityContext(Users, Roles);
Database.DropCollection("users");
Database.DropCollection("roles");
}
示例10: MongoGridFS
/// <summary>
/// Initializes a new instance of the MongoGridFS class.
/// </summary>
/// <param name="database">The database containing the GridFS collections.</param>
/// <param name="settings">The GridFS settings.</param>
public MongoGridFS(MongoDatabase database, MongoGridFSSettings settings)
{
settings = settings.Clone();
settings.ApplyDefaultValues(database.Settings);
settings.Freeze();
_database = database;
_settings = settings;
_chunks = database.GetCollection(settings.Root + ".chunks");
_files = database.GetCollection(settings.Root + ".files");
}
示例11: PlaceService
public PlaceService()
{
var connectionString = appSettings.Get ("MongoDB", "");
client = new MongoClient (connectionString);
server = client.GetServer ();
db = server.GetDatabase ("geoapi");
placescollection = db.GetCollection<PlaceResponse> ("place");
triggerscollection = db.GetCollection<Trigger> ("trigger");
if (!BsonClassMap.IsClassMapRegistered (typeof(PlaceResponse))) {
BsonClassMap.RegisterClassMap<PlaceResponse> ();
}
}
示例12: MongoDBEventStore
public MongoDBEventStore(string connectionString = DEFAULT_DATABASE_URI, IEventTypeResolver typeResolver = null, IEventConverter converter = null)
{
_database = MongoDatabase.Create(connectionString);
_commits = _database.GetCollection<MongoCommit>("Commits");
_events = _database.GetCollection<BsonDocument>("SourcedEvents");
_converter = converter ?? new NullEventConverter();
_formatter = new JsonEventFormatter(typeResolver ?? new SimpleEventTypeResolver());
_translator = new StringEventTranslator();
EnsureIndexes();
}
示例13: MongoDbPostRepository
public MongoDbPostRepository(IMongoConnectionFactory connectionFactory)
{
db = connectionFactory.Create();
db.GetCollection("posts").EnsureIndex(
IndexKeys.Descending("Slug", "Version"),
IndexOptions.SetUnique(true));
db.GetCollection("sequences").EnsureIndex(
IndexKeys.Descending("Name"),
IndexOptions.SetUnique(true));
}
示例14: StartPlace
/// <summary>
/// 清理用户名
/// </summary>
/// <param name="note"></param>
public void StartPlace()
{
string connectionString = ConfigLoader.Config.DbPlayer;
database = MongoDatabase.Create(connectionString);
MongoCollection player = database.GetCollection("Player");
int count = NewMethod(player, "UserID");
Console.WriteLine("Player:" + count);
MongoCollection user = database.GetCollection("UserLog");
count = NewMethod2(user);
Console.WriteLine("UserLog" + count);
}
示例15: Repository
public Repository(string connection)
{
if (string.IsNullOrWhiteSpace(connection))
{
connection = "mongodb://notb544:27017";
}
_client = new MongoClient(connection);
_server = _client.GetServer();
_database = _server.GetDatabase("local", WriteConcern.Unacknowledged);
_corporation = _database.GetCollection<Corporation>("Corporations");
_realEstate = _database.GetCollection<RealEstate>("RealEstates");
}