public void CreateDatabase() { if (!_db.CollectionExists(_settings.ClientCollection)) { _db.CreateCollection(_settings.ClientCollection); } if (!_db.CollectionExists(_settings.ScopeCollection)) { _db.CreateCollection(_settings.ScopeCollection); } if (!_db.CollectionExists(_settings.ConsentCollection)) { MongoCollection <BsonDocument> collection = _db.GetCollection(_settings.ConsentCollection); collection.CreateIndex("subject"); } var tokenCollections = new[] { _settings.AuthorizationCodeCollection, _settings.RefreshTokenCollection, _settings.TokenHandleCollection }; foreach (string tokenCollection in tokenCollections) { if (!_db.CollectionExists(tokenCollection)) { MongoCollection <BsonDocument> collection = _db.GetCollection(tokenCollection); collection.CreateIndex("_clientId", "_subjectId"); } } }
private void Create() { ClientMongo = new MongoClient(); DatabaseMongo = ClientMongo.GetServer().GetDatabase(this.DbName); if (!DatabaseMongo.CollectionExists("files")) { DatabaseMongo.CreateCollection("files"); } files = DatabaseMongo.GetCollection <BsonDocument>("files"); files.CreateIndex("FileId"); files.CreateIndex("BlockId"); files.CreateIndex("ClassName"); if (!DatabaseMongo.CollectionExists("objects")) { DatabaseMongo.CreateCollection("objects"); } objects = DatabaseMongo.GetCollection <BsonDocument>("objects"); objects.CreateIndex("ClassName"); objects.CreateIndex("ObjectId"); objects.CreateIndex("FileId"); }
public void TestCreateCollection() { var collectionName = "testcreatecollection"; Assert.False(_database.CollectionExists(collectionName)); _database.CreateCollection(collectionName); Assert.True(_database.CollectionExists(collectionName)); }
public Initializer(MongoDatabase database) { _database = database; if (!_database.CollectionExists(Collections.USERS)) _database.CreateCollection(Collections.USERS); if (!_database.CollectionExists(Collections.TODOS)) _database.CreateCollection(Collections.TODOS); }
public MongoAtHomeDataRepository() { _mongoServer = MongoServer.Create(ApplicationSettings.MongoDBConnectionString); _mongoDatabase = _mongoServer.GetDatabase(_dbName); if (!_mongoDatabase.CollectionExists("clientinformation")) _mongoDatabase.CreateCollection("clientinformation"); if (!_mongoDatabase.CollectionExists("workunit")) _mongoDatabase.CreateCollection("workunit"); }
private void PrepareDatabase() { var collectionNames = _database.GetCollectionNames().ToList().FindAll(x => x != "system.indexes" && x != "system.users"); collectionNames.ForEach(c => _database.DropCollection(c)); _database.DropCollection(Collection1); _database.DropCollection(Collection2); _database.CreateCollection(Collection1); _database.CreateCollection(Collection2); }
void Initialize() { _server = MongoServer.Create(_configuration.Url); _database = _server.GetDatabase(_configuration.DefaultDatabase); if (!_database.CollectionExists(CollectionName)) _database.CreateCollection(CollectionName); _collection = _database.GetCollection(CollectionName); if (!_database.CollectionExists(IncrementalKeysCollectionName)) _database.CreateCollection(IncrementalKeysCollectionName); _incrementalKeysCollection = _database.GetCollection(IncrementalKeysCollectionName); }
public void Handle(NewBenefitDefinedEvent args) { if (_mongoDataBase.CollectionExists("Benefits") == false) { _mongoDataBase.CreateCollection("Benefits"); } var benefitsCollection = _mongoDataBase.GetCollection <BenefitDto>("Benefits"); var benefit = new BenefitDto { Id = args.BenefitId, BenefitType = args.BenefitType, Description = args.BenefitDescription, HasMaxElectionAmount = args.HasMaxElectionAmount, MaxElectionAmount = args.MaxElectionAmount, PlanId = args.PlanId, CompanyId = args.CompanyId, }; var safeModeResult = benefitsCollection.Save(benefit); if (!safeModeResult.Ok) { //log! //push a message to an admin q? } }
public MongoQueue(MongoQueConfig config) { // our queue name will be the same as the message class _database = MongoDatabase.Create(config.ConnectionString); if (!_database.CollectionExists(_queueName)) { try { Log.InfoFormat("Creating queue '{0}' size {1}", _queueName, config.QueueSize); var options = CollectionOptions .SetCapped(true) // use a capped collection so space is pre-allocated and re-used .SetAutoIndexId(true) .SetMaxSize(config.QueueSize); // limit the size of the collection and pre-allocated the space to this number of bytes _database.CreateCollection(_queueName, options); var col = _database.GetCollection(_queueName); col.EnsureIndex(new[] { "Dequeued" }); col.EnsureIndex(new[] { "Equeued" }); } catch { // assume that any exceptions are because the collection already exists ... } } // get the queue collection for our messages _queue = _database.GetCollection <MongoMessage <T> >(_queueName); }
public static void InsertErpOrderPartner(string orderId, string parNr, MongoDatabase mongoDatabase, ILogger logger) { string collName = "erpOrderPartner"; if (!mongoDatabase.CollectionExists(collName)) { logger.LogDebug("Collection doesn't exist. Creating it.", collName); mongoDatabase.CreateCollection(collName); MongoCollection <BsonDocument> newErpEntriesCollection = mongoDatabase.GetCollection(collName); IndexKeysBuilder Key = IndexKeys.Ascending("orderid"); newErpEntriesCollection.CreateIndex(Key); } MongoCollection <BsonDocument> erpEntriesCollection = mongoDatabase.GetCollection(collName); MongoCursor cursor = erpEntriesCollection.Find(Query.And(Query.EQ("orderid", orderId), Query.EQ("parnr", parNr))); if (cursor.Count() == 0) { BsonDocument orderPartnerDocument = new BsonDocument(); ObjectId currentProcess_id = ObjectId.GenerateNewId(); orderPartnerDocument.Set(DBQuery.Id, currentProcess_id); orderPartnerDocument.Set("orderid", orderId); orderPartnerDocument.Set("parnr", parNr); orderPartnerDocument.Set("created", DateTime.UtcNow); erpEntriesCollection.Save(orderPartnerDocument, WriteConcern.Acknowledged); } }
/// <summary> /// Verifies the the MongoDatabase collection exists or creates it if it doesn't. /// </summary> /// <param name="logDb"></param> protected void VerifyCollection(MongoDatabase logDb) { if (!logDb.CollectionExists(_collectionName)) { logDb.CreateCollection(_collectionName, _collectionCreationOptions); } }
public bool InsertProductMongoCollection() { var collection = _database.GetCollection <BsonDocument>("Products"); var doesCollectionExist = collection.Database.CollectionExists("Products"); try { if (!doesCollectionExist) { var client = new MongoClient(); var MongoDB = client.GetDatabase("ProductsDataBase"); _database.CreateCollection("Products"); var clientCollection = _database.GetCollection <BsonDocument>("Products"); var products = GetJsonProductList(); var bsonDocumentList = products.Select(product => product.ToBsonDocument()).ToList(); foreach (var document in bsonDocumentList) { clientCollection.Insert(document); } return(true); } } catch (Exception) { return(false); } return(doesCollectionExist); }
private static void CreateCollectionIfNecessary(MongoDatabase database) { if (!database.CollectionExists(CollectionName)) { database.CreateCollection(CollectionName); } }
public void setUp() { wammerDb = mongodb.GetDatabase("wammer"); if (wammerDb.CollectionExists("attachments")) { wammerDb.DropCollection("attachments"); } wammerDb.CreateCollection("attachments"); objectId1 = Guid.NewGuid().ToString(); doc = new Attachment { object_id = objectId1, title = "title1", description = "description1" }; AttachmentCollection.Instance.Save(doc); handler = new AttachmentGetHandler(); server = new HttpServer(8080); server.AddHandler("/api/get/", handler); server.Start(); //host = new WebServiceHost(svc, new Uri("http://localhost:8080/api/")); //host.Open(); }
MongoCollection <BsonDocument> check_table(string tablename, string indexname = "") { MongoCollection <BsonDocument> tmp = null; try { if (!mMongodbClient.CollectionExists(tablename)) { CommandResult cr = mMongodbClient.CreateCollection(tablename); tmp = mMongodbClient.GetCollection(tablename); } else { tmp = mMongodbClient.GetCollection(tablename); } if (indexname != "" && !tmp.IndexExists(indexname)) { tmp.CreateIndex(indexname); } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(tmp); }
public MongoCollection <BsonDocument> check_table_keys(string tablename, string[] indexes = null) { MongoCollection <BsonDocument> tmp = null; try { if (!mMongodbClient.CollectionExists(tablename)) { CommandResult cr = mMongodbClient.CreateCollection(tablename); tmp = mMongodbClient.GetCollection(tablename); } else { tmp = mMongodbClient.GetCollection(tablename); } if (indexes != null && indexes.Length > 0) { foreach (var it in indexes) { if (it != "" && !tmp.IndexExists(it)) { tmp.CreateIndex(it); } } } } catch (Exception ex) { LOGW.Info(ex.ToString()); } return(tmp); }
static void Main(string[] args) { MongoServer dbServer = MongoServer.Create(); dbServer.Connect(); MongoDatabase db = dbServer.GetDatabase("test"); if (db.GetCollection("items") == null) { db.CreateCollection("items"); BsonDocument document = new BsonDocument { { "SKU", "I001" }, { "Variant", "Tubes" }, { "Quantity", "10" }, { "Cost", "150.50" } }; db["items"].Insert <BsonDocument>(document); } Console.WriteLine(db["items"].FindOne()); dbServer.Disconnect(); Console.ReadLine(); }
/// <summary> /// Create Collection /// </summary> /// <param name="strObjTag"></param> /// <param name="treeNode"></param> /// <param name="collectionName"></param> /// <returns></returns> public static Boolean CreateCollection(String strObjTag, TreeNode treeNode, String collectionName) { //不支持中文 JIRA ticket is created : SERVER-4412 //SERVER-4412已经在2013/03解决了 //collection names are limited to 121 bytes after converting to UTF-8. Boolean rtnResult = false; MongoDatabase mongoDB = GetMongoDBBySvrPath(strObjTag); String strSvrPath = SystemManager.GetTagData(strObjTag); String svrKey = strSvrPath.Split("/".ToCharArray())[(int)PathLv.InstanceLv]; String ConKey = strSvrPath.Split("/".ToCharArray())[(int)PathLv.ConnectionLv]; if (mongoDB != null) { if (!mongoDB.CollectionExists(collectionName)) { mongoDB.CreateCollection(collectionName); foreach (TreeNode item in treeNode.Nodes) { if (item.Tag.ToString().StartsWith(COLLECTION_LIST_TAG)) { item.Nodes.Add(UIHelper.FillCollectionInfoToTreeNode(collectionName, mongoDB, ConKey + "/" + svrKey)); } } rtnResult = true; } } return(rtnResult); }
public void BankAccountsCollection(MongoDatabase db) { if (db.CollectionExists("BankAccounts") == false) { db.CreateCollection("BankAccounts"); } }
static void Main(string[] args) { MongoServer ms = MongoServer.Create(); string _dbName = "docs"; MongoDatabase md = ms.GetDatabase(_dbName); if (!md.CollectionExists(_dbName)) { md.CreateCollection(_dbName); } MongoCollection <Doc> _documents = md.GetCollection <Doc>(_dbName); _documents.RemoveAll(); //add file to GridFS MongoGridFS gfs = new MongoGridFS(md); MongoGridFSFileInfo gfsi = gfs.Upload(@"c:\mongodb.rtf"); _documents.Insert(new Doc() { DocId = gfsi.Id.AsObjectId, DocName = @"c:\foo.rtf" } ); foreach (Doc item in _documents.FindAll()) { ObjectId _documentid = new ObjectId(item.DocId.ToString()); MongoGridFSFileInfo _fileInfo = md.GridFS.FindOne(Query.EQ("_id", _documentid)); gfs.Download(item.DocName, _fileInfo); Console.WriteLine("Downloaded {0}", item.DocName); Console.WriteLine("DocName {0} dowloaded", item.DocName); } Console.ReadKey(); }
/// <summary> /// Create Collection /// </summary> /// <param name="strObjTag"></param> /// <param name="treeNode"></param> /// <param name="collectionName"></param> /// <returns></returns> public static Boolean CreateCollection(String strObjTag, TreeNode treeNode, String collectionName) { Boolean rtnResult = false; MongoDatabase mongoDB = GetMongoDBBySvrPath(strObjTag); String strSvrPath = SystemManager.GetTagData(strObjTag); String svrKey = strSvrPath.Split("/".ToCharArray())[(int)PathLv.ServerLV]; String ConKey = strSvrPath.Split("/".ToCharArray())[(int)PathLv.ConnectionLV]; if (mongoDB != null) { if (!mongoDB.CollectionExists(collectionName)) { mongoDB.CreateCollection(collectionName); foreach (TreeNode item in treeNode.Nodes) { if (item.Tag.ToString().StartsWith(COLLECTION_LIST_TAG)) { item.Nodes.Add(FillCollectionInfoToTreeNode(collectionName, mongoDB, ConKey + "/" + svrKey)); } } rtnResult = true; } } return(rtnResult); }
private void CreateCollections() { HashSet <string> collectionsName = new HashSet <string>(); IAsyncCursor <string> collectionNameCursor = MongoDatabase.ListCollectionNames(); while (collectionNameCursor.MoveNext()) { foreach (string colName in collectionNameCursor.Current) { collectionsName.Add(colName); } } foreach (PropertyInfo prop in GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Instance)) { if (prop.PropertyType.Name != typeof(IMongoCollection <>).Name) { throw new Exception($"Property {prop.Name} is not {typeof(IMongoCollection<>).Name}<> type"); } if (!collectionsName.Contains(prop.Name)) { MongoDatabase.CreateCollection(prop.Name); } object mongoCollection = typeof(IMongoDatabase).GetMethod(nameof(MongoDatabase.GetCollection)).MakeGenericMethod(prop.PropertyType.GenericTypeArguments.First()).Invoke(MongoDatabase, new[] { prop.Name, null }); prop.SetValue(this, mongoCollection); } }
public void UsersCollection(MongoDatabase db) { if (db.CollectionExists("Users") == false) { db.CreateCollection("Users"); } }
public void TransactionsCollection(MongoDatabase db) { if (db.CollectionExists("Transactions") == false) { db.CreateCollection("Transactions"); } }
public void FamilyMembersCollection(MongoDatabase db) { if (db.CollectionExists("FamilyMembers") == false) { db.CreateCollection("FamilyMembers"); } }
/// <summary> /// Verifies the the MongoDatabase collection exists or creates it if it doesn't. /// </summary> protected void VerifyCollection() { if (!_mongoDatabase.CollectionExists(_collectionName)) { _mongoDatabase.CreateCollection(_collectionName, _collectionCreationOptions); } }
protected override void CreateCollection(MongoDatabase database) { CollectionOptionsBuilder options = CollectionOptions .SetCapped(true) .SetMaxSize(5 * 1024 * 1024); database.CreateCollection(GetCollectionName(), options); }
private void CreateElevatorCollectionIfItDoesntExist() { GuardForInitialized(); if (!database.CollectionExists(SpecialCollectionNameForElevator)) { database.CreateCollection(SpecialCollectionNameForElevator); } }
void Initialize() { _server = MongoServer.Create(_configuration.Url); _database = _server.GetDatabase(_configuration.DefaultDatabase); if (!_database.CollectionExists(CollectionName)) { _database.CreateCollection(CollectionName); } _collection = _database.GetCollection(CollectionName); if (!_database.CollectionExists(IncrementalKeysCollectionName)) { _database.CreateCollection(IncrementalKeysCollectionName); } _incrementalKeysCollection = _database.GetCollection(IncrementalKeysCollectionName); }
static void connect() { server = MongoServer.Create(dbURL); database = server.GetDatabase("void"); if (!database.CollectionExists(dbName)) { database.CreateCollection(dbName); } }
void Initialize() { _server = MongoServer.Create(_configuration.Url); _database = _server.GetDatabase(_configuration.DefaultDatabase); if (!_database.CollectionExists(CollectionName)) _database.CreateCollection(CollectionName); _collection = _database.GetCollection<EventSubscription>(CollectionName); }
public MongoCollection <T> GetCollection <T>(string collectionName, IMongoCollectionOptions options) where T : class { if (!_database.GetCollectionNames().Contains(collectionName)) { _database.CreateCollection(collectionName, options); } return(_database.GetCollection <T>(collectionName)); }
/// <summary> /// Js数据集初始化 /// </summary> public static void InitJavascript() { MongoDatabase mongoDB = SystemManager.GetCurrentDataBase(); if (!mongoDB.CollectionExists(COLLECTION_NAME_JAVASCRIPT)) { mongoDB.CreateCollection(COLLECTION_NAME_JAVASCRIPT); } }
/// <summary> /// 数据库User初始化 /// </summary> public static void InitDBUser() { MongoDatabase mongoDB = SystemManager.GetCurrentDataBase(); if (!mongoDB.CollectionExists(COLLECTION_NAME_USER)) { mongoDB.CreateCollection(COLLECTION_NAME_USER); } }
/// <summary> /// GFS初始化 /// </summary> public static void InitGFS() { MongoDatabase mongoDB = SystemManager.GetCurrentDataBase(); if (!mongoDB.CollectionExists(COLLECTION_NAME_GFS_FILES)) { mongoDB.CreateCollection(COLLECTION_NAME_GFS_FILES); } }
/// <summary> /// 带有参数的CreateOption /// </summary> /// <param name="strObjTag"></param> /// <param name="collectionName"></param> /// <param name="option"></param> /// <param name="mongoDb"></param> /// <returns></returns> public static bool CreateCollectionWithOptions(string strObjTag, string collectionName, CollectionOptionsBuilder option, MongoDatabase mongoDb) { //不支持中文 JIRA ticket is created : SERVER-4412 //SERVER-4412已经在2013/03解决了 //collection names are limited to 121 bytes after converting to UTF-8. if (mongoDb == null) return false; if (mongoDb.CollectionExists(collectionName)) return false; mongoDb.CreateCollection(collectionName, option); return true; }
public MongoDocumentWriter(string connectionString, string databaseName, string collectionName) { var id = new ObjectId(); var server = new MongoClient(connectionString).GetServer(); _db = server.GetDatabase(databaseName); if (_db.CollectionExists(collectionName)) _db.DropCollection(collectionName); _db.CreateCollection(collectionName); _collection = _db.GetCollection(collectionName); }
public ObjectStore() { var connectionString = ConfigurationManager.AppSettings.Get("MONGOLAB_URI"); var server = MongoServer.Create(connectionString); _database = server.GetDatabase("appharbor_a6a88884-0e19-42c8-92ed-6ec23821b99d"); var exists = _database.CollectionExists(SubscribersKey); if (!exists) { _database.CreateCollection(SubscribersKey); } }
//public MongoDatabase GetDatabase() //{ // //MongoServer server = MongoServer.Create(ConnectionString); // //MongoCredential cred = new MongoCredential("test", // ////MongoCredentials cred = new MongoCredentials(UserName, PassWord); // //MongoDatabase db = server.GetDatabase(DatabaseName, cred); // //return db; //} public bool CreateCollection(MongoDatabase db, string collectionname) { try { if (db.CollectionExists(collectionname) == false) { db.CreateCollection(collectionname); return true; } else { return true; } } catch (Exception) { return false; } }
private static void DropAndCreateCollections(MongoDatabase db, string[] collections) { string[] names = Enumerable.ToArray<string>(db.GetCollectionNames()); foreach (string name in names) { if (collections.Contains(name)) { db.DropCollection(name); } } foreach (string collection in collections) { db.CreateCollection(collection); } }
public override void Up(MongoDatabase database) { database.CreateCollection("Users"); }