GetServer() public method

Gets a MongoServer object using this client's settings.
public GetServer ( ) : MongoServer
return MongoServer
 private MongoDatabase RetreiveMongohqDb()
 {
     MongoClient mongoClient = new MongoClient(
         new MongoUrl(ConfigurationManager.ConnectionStrings["MongoHQ"].ConnectionString));
     MongoServer server = mongoClient.GetServer();
     return mongoClient.GetServer().GetDatabase("MyFirstDb");
 }
        public static Configure MongoPersistence(this Configure config)
        {
            var connectionStringEntry = ConfigurationManager.ConnectionStrings["NServicebus.Persistence"];

            //user existing config if we can find one
            if (connectionStringEntry != null)
                return MongoPersistenceWithConectionString(config, connectionStringEntry.ConnectionString, null);

            var client = new MongoClient(MongoPersistenceConstants.DefaultUrl);
            var db = client.GetServer().GetDatabase(DatabaseNamingConvention());

            return MongoPersistence(config, client.GetServer(), db);
        }
Example #3
0
        public static void Insert()
        {
            MongoClient client = new MongoClient(strconn);
            client.GetServer();
            //创建数据库链接
            MongoServer server = client.GetServer();// MongoDB.Driver.MongoServer.Create(strconn);
            //获得数据库
            MongoDatabase db = server.GetDatabase(dbName);

            Persons person = new Persons();
            person.name = "44444";
            person.age = 24;
            MongoCollection col = db.GetCollection("person");
            col.Insert<Persons>(person);
        }
        public void Connect(string name = DefaultDbName)
        {
            var client = new MongoClient(DefaultConnectionString);
            var server = client.GetServer();

            this.Database = server.GetDatabase(name);
        }
Example #5
0
 public MdbAccount()
 {
     m_Client = new MongoClient(Configuration.Database.Url);
     m_Server = m_Client.GetServer();
     m_Database = m_Server.GetDatabase(Configuration.Database.Name);
     m_Collection = m_Database.GetCollection<Account>(MDBAccountTable);
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="connectionString"></param>
 /// <param name="databaseName"></param>
 public MongoDBAggregatorPersistor(string connectionString, string databaseName)
 {
     var mongoClient = new MongoClient(connectionString);
     MongoServer server = mongoClient.GetServer();
     var mongoDatabase = server.GetDatabase(databaseName);
     _collection = mongoDatabase.GetCollection<MongoDbData<object>>("Aggregator");
 }
Example #7
0
 public static MongoCollection<BsonDocument> GetCollection(string collectionName)
 {
     var mongoclient = new MongoClient(ConfigurationManager.ConnectionStrings["MongoDB"].ConnectionString);
         var server = mongoclient.GetServer();
         var MongoDatabase = server.GetDatabase("CVServicePoc");
         return MongoDatabase.GetCollection(collectionName);
 }
Example #8
0
        static void Main(string[] args)
        {
            //ExecQueryMongoDBTest();

            LINQTutorialCall();

            //InsertToMongoDBFile();

            var connectionString = "mongodb://localhost";
            var client = new MongoClient(connectionString);
            var server = client.GetServer();
            var database = server.GetDatabase("test");
            var collection = database.GetCollection<Entity>("entities");

            var entity = new Entity { Name = "Tom" };
            collection.Insert(entity);
            var id = entity.Id;

            var query = Query<Entity>.EQ(e => e.Id, id);
            entity = collection.FindOne(query);

            entity.Name = "Dick";
            collection.Save(entity);

            var update = Update<Entity>.Set(e => e.Name, "Harry");
            collection.Update(query, update);

            collection.Remove(query);


        }
 /// <summary>
 /// Initializes a new instance of the <see cref="MongoSystemEventLogger"/> class.
 /// </summary>
 /// <param name="configuration">The configuration options.</param>
 public MongoSystemEventLogger(IMongoConfiguration configuration)
 {
     this.Configuration = configuration;
     MongoClient client = new MongoClient(configuration.ToMongoClientSettings());
     this.Server = client.GetServer();
     this.Database = this.Server.GetDatabase(configuration.Database);
 }
    static void Main()
    {
        var client = new MongoClient("mongodb://localhost/");
        var server = client.GetServer();
        var dictionaryDb = server.GetDatabase("Dictionary");
        var english = dictionaryDb.GetCollection("English");

        Console.WriteLine("Enter command - Add, Change, Find or Exit");
        string command = Console.ReadLine();
        while (command != exit)
        {
            if (command == add)
            {
                AddToDictionary(english);
            }
            else if (command == change)
            {
                ChangeTranslation(english);
            }
            else if (command == find)
            {
                ShowTranslation(english);
            }
            else if (command != exit)
            {
                Console.WriteLine("Enter invalid command. Please try again.");
            }

            Console.WriteLine("Enter command - Add, Change, Find or Exit");
            command = Console.ReadLine();
        }
    }
Example #11
0
        public MongoContext()
        {
            var client = new MongoClient(ConfigurationManager.ConnectionStrings[DATABASE].ConnectionString);
            var server = client.GetServer();

            _database = server.GetDatabase(DATABASE);
        }
        private void ConnectLocal(string dbName)
        {
            var client = new MongoClient(ConnStringLocal);
            var server = client.GetServer();

            this.Database = server.GetDatabase(dbName);
        }
 private MongoCollection<BsonDocument> GetMongoCollection()
 {
     var client = new MongoClient(_connectionString);
     var db = client.GetServer().GetDatabase(new MongoUrl(_connectionString).DatabaseName);
     var collection = db.GetCollection(_collectionName);
     return collection;
 }
 public static void EstablishConnection()
 {
     client = new MongoClient(connectionString);
     server = client.GetServer();
     database = server.GetDatabase(DbName);
     entries = database.GetCollection<JSonReport>(collectionName);
 }
 public MigrationRunner(string connectionString, string databaseName, string collectionName = DEFAULT_COLLECTION_NAME)
 {
     var client = new MongoClient(connectionString);
     Database = client.GetServer().GetDatabase(databaseName);
     DatabaseStatus = new DatabaseMigrationStatus(this);
     MigrationLocator = new MigrationLocator();
 }
Example #16
0
 public BaseRepository(string collection)
 {
     _collectionName = collection;
     var client = new MongoClient(ConfigurationManager.ConnectionStrings["mongodb"].ConnectionString);
     var db = client.GetServer().GetDatabase(ConfigurationManager.ConnectionStrings["mongodb"].ProviderName);
     _collection = db.GetCollection(_collectionName);
 }
Example #17
0
 public static MongoDatabase GetDBFromConnection(String connectionName)
 {
     var url = GetMongoDBUrl(connectionName);
     var client = new MongoClient(url);
     var server = client.GetServer();
     return server.GetDatabase(url.DatabaseName);
 }
Example #18
0
        public static List<ProductReportEntity> GetProductReports()
        {
            List<ProductReportEntity> result = new List<ProductReportEntity>();

            string mongoConnectionString = @"mongodb://192.168.193.25:27017/productReport";
            MongoClient client = new MongoClient(mongoConnectionString);
            MongoServer server = client.GetServer();
            MongoDatabase productReportsDb = server.GetDatabase("productReport");

            MongoCollection<ProductReportEntity> reportsCollection = productReportsDb.GetCollection<ProductReportEntity>("reports");
            var reports =
                from report in reportsCollection.AsQueryable<ProductReportEntity>()
                select report;

            foreach (var report in reports)
            {
                ProductReportEntity newReport = new ProductReportEntity();
                newReport.ProductName = report.ProductName;
                newReport.VendorName = report.VendorName;
                newReport.TotalIncomes = report.TotalIncomes;
                newReport.TotalQuantitySold = report.TotalQuantitySold;

                result.Add(newReport);
            }

            return result;
        }
Example #19
0
 public MongoDictionary(string connectionString, string databaseName, string collectionName)
 {
     var client = new MongoClient(connectionString);
     var server = client.GetServer();
     var database = server.GetDatabase(databaseName);
     entriesCollection = database.GetCollection<Entry>(collectionName);
 }
 public WellCastServerEngine()
 {
     //Get a Reference to the Client Object
     var mongoClient = new MongoClient( "mongodb://*****:*****@ds041140.mongolab.com:41140/wellcast");
     var mongoServer = mongoClient.GetServer();
     mdb = mongoServer.GetDatabase("wellcast");
 }
Example #21
0
    public bool IsRestored(string connectionName)
    {
      MongoServer server = null;
      var connectionString = ConfigurationManager.ConnectionStrings[connectionName]?.ConnectionString;

      if (string.IsNullOrEmpty(connectionString))
      {
        return false;
      }

      try
      {
        var mongoUrl = new MongoUrl(connectionString);
        var mongoClient = new MongoClient(mongoUrl);
        server = mongoClient.GetServer();

        return server.GetDatabase(mongoUrl.DatabaseName).CollectionExists(MongoRestoreSettings.RestoredDbTokenCollection);
      }
      catch (FormatException ex)
      {
        Log.Error("Wrong connection string format", ex, this);
        throw;
      }
      finally
      {
        server?.Disconnect();
      }
    }
Example #22
0
 public static MongoCollection<Employee> Open()
 {
     var client = new MongoClient("mongodb://localhost");
     var server = client.GetServer();
     var db = server.GetDatabase("Employees");
     return db.GetCollection<Employee>("employees");
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MongoWorkflowDataAccess"/> class.
 /// </summary>
 /// <param name="configuration">The configuration options.</param>
 public MongoWorkflowDataAccess(IMongoConfiguration configuration)
 {
     this.Configuration = configuration;
     MongoClient client = new MongoClient(configuration.ToMongoClientSettings());
     this.Server = client.GetServer();
     this.Database = this.Server.GetDatabase(configuration.Database);
 }
Example #24
0
 public MongoUtil()
 {
     connectionString = "mongodb://localhost";
     client  = new MongoClient(connectionString);
     server = client.GetServer();
     database = server.GetDatabase("testwechat");
 }
        public static void ExecuteMongo()
        {
            const string connectionString = "mongodb://localhost";
            var client = new MongoClient(connectionString);
            var server = client.GetServer();
            var database = server.GetDatabase("Polyglot");
            var directory = database.GetCollection<RootDirectory>("rootdirectory");
            directory.Remove(new QueryDocument());

            byte[] inputBytes = System.Text.Encoding.Unicode.GetBytes("password");//will need to change to being the user input
            SHA256Managed hashstring = new SHA256Managed();
            byte[] dbHash = hashstring.ComputeHash(inputBytes);

            directory.Insert(new RootDirectory()
            {
                _id = ObjectId.GenerateNewId().ToString(),
                un = "harageth",
                pw = System.Text.Encoding.UTF8.GetString(dbHash),//need to encrypt this password
                folders = new List<Folder>() { new Folder() { folderName = "firstFolder", files = new List<string>() { "temp1.txt", "file1.txt" } }, new Folder() { folderName = "secondFolder", files = new List<string>() { "temp2.txt", "file2.txt" } }, new Folder() { folderName = "thirdFolder", files = new List<string>() { "temp3.txt", "file3.txt" } } },
                files = new List<string>( ) { "temp.txt", "file.txt" }

            });

            directory.Insert(new RootDirectory()
            {
                _id = ObjectId.GenerateNewId().ToString(),
                un = "Guest",
                //folders = new List<Folder>() { new Folder() { folderName = "firstFolder", files = new List<string>() { "temp1.txt", "file1.txt" } }, new Folder() { folderName = "secondFolder", files = new List<string>() { "temp2.txt", "file2.txt" } }, new Folder() { folderName = "thirdFolder", files = new List<string>() { "temp3.txt", "file3.txt" } } },
                //files = new List<string>() { "temp.txt", "file.txt" }

            });
        }
 public static MongoDbWorkflowStore MongoDbStore()
 {
     var client = new MongoClient("mongodb://localhost");
     var server = client.GetServer();
     var database = server.GetDatabase("StatelessWorkflowTest");
     return new MongoDbWorkflowStore(database);
 }
        static void Main()
        {
            string decorationLine = new string('-', Console.WindowWidth);
            Console.Write(decorationLine);
            Console.WriteLine("***Dictionary application with options for adding a new entry,");
            Console.WriteLine("listing all entries from it and finding the translation of a given word***");
            Console.Write(decorationLine);

            // Start MongoDB server
            var mongoClient = new MongoClient(Settings.Default.MongoDBConnectionString);
            var mongoServer = mongoClient.GetServer();
            var dictionaryDB = mongoServer.GetDatabase("DictionaryDB");
            var dictionary = dictionaryDB.GetCollection<DictionaryEntry>("Dictionary");

            ConsoleKeyInfo command = new ConsoleKeyInfo();
            while (true)
            {
                DisplayMenu();

                command = Console.ReadKey();
                if (command.Key == ConsoleKey.Escape)
                {
                    Console.WriteLine();
                    break;
                }

                ProccessCommand(dictionary, command);
            }
        }
        public static bool InitMongoDB(this Funq.Container container)
        {
            try
            {
                // Register the MySql Database Connection Factory
                var mongoDbConnectionString = ConfigurationManager.ConnectionStrings["MongoDB"].ConnectionString;
                var client = new MongoClient(mongoDbConnectionString);
                var server = client.GetServer();
                var database = server.GetDatabase("hello_world");
                container.Register<MongoDatabase>(c => database);

                BsonClassMap.RegisterClassMap<World>(cm => {
                    cm.MapProperty(c => c.id);
                    cm.MapProperty(c => c.randomNumber);
                });

                BsonClassMap.RegisterClassMap<Fortune>(cm => {
                    cm.MapProperty(c => c.id);
                    cm.MapProperty(c => c.message);
                });

                // Create needed tables in MySql Server if they do not exist
                return database.CreateWorldTable() && database.CreateFortuneTable();
            }
            catch
            {
                // Unregister failed database connection factory
                container.Register<MongoDatabase>(c => null);

                return false;
            }

        }
Example #29
0
 public MongoDatabase GetMongoContext()
 {
     MongoClient client = new MongoClient(path);
     MongoServer server = client.GetServer();
     MongoDatabase dbContext = server.GetDatabase("mongotelerikchat");
     return dbContext;
 }
 static MongoRepositoryContext() {
     settings = new MongoRepositorySettings();
     var url = new MongoUrl(ConfigurationManager.ConnectionStrings["SysDB"].ConnectionString);
     client = new MongoClient(url);
     server = client.GetServer();
     database = server.GetDatabase(url.DatabaseName);
 }
Example #31
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MongoGateway" /> class.
        /// </summary>
        /// <param name="serverName">Name of the server should be lke this "mongodb://localhost".</param>
        /// <param name="databaseName">Name of the database.</param>
        public MongoDBContext(string connectionString)
        {
            var databaseName = MongoUrl.Create(connectionString).DatabaseName;
            var mongoClient  = new MongoDB.Driver.MongoClient(connectionString);

            _server   = mongoClient.GetServer();
            _database = _server.GetDatabase(databaseName);
        }
Example #32
0
        public string GetVAData(string criteria)
        {
            var client = new MongoDB.Driver.MongoClient("mongodb://anighthawks2.cloudapp.net:27017");
            var server = client.GetServer();
            var db     = server.GetDatabase("vaMongo");

            try
            {
                MongoCollection <BsonDocument> healthrecords = db.GetCollection <BsonDocument>("healthRecords");
                BsonDocument mongoDoc = healthrecords.FindOneAs <BsonDocument>();

                switch (criteria)
                {
                case "demographics":
                {
                    return(mongoDoc["DEMOGRAPHICS"].AsBsonDocument.ToJson());

                    break;
                }

                case "account_summary":
                {
                    return(mongoDoc["MY HEALTHEVET ACCOUNT SUMMARY"].AsBsonDocument.ToJson());

                    break;
                }

                case "care_providers":
                {
                    return(mongoDoc["HEALTH CARE PROVIDERS"].AsBsonDocument.ToJson());

                    break;
                }

                case "medication history":
                {
                    return(mongoDoc["MEDICATION HISTORY"].AsBsonDocument.ToJson());

                    break;
                }

                default:
                {
                    return(null);

                    break;
                }
                }
            }
            catch
            {
                return(string.Empty);
            }

            return(string.Empty);
        }
Example #33
0
    public static void Set(MongoDB.Driver.MongoClient c, String k, BsonDocument v)
    {
        var    db     = c.GetServer().GetDatabase("db");
        var    coll   = db.GetCollection(k);
        Entity entity = new Entity {
            data = v, _id = k
        };

        coll.Save(entity);
    }
        public DaoCaso()
        {
            var cliente = new MongoDB.Driver.MongoClient(connect);

            server = cliente.GetServer();

            database = server.GetDatabase("sojaBD");


            coll = database.GetCollection <Caso>("casos");
        }
Example #35
0
        public DaoAtributo()
        {
            var cliente = new MongoDB.Driver.MongoClient(connect);

            server = cliente.GetServer();

            database = server.GetDatabase("sojaBD");


            coll = database.GetCollection <Atributo>("atrib_values");
        }
Example #36
0
    public static Object Get(MongoDB.Driver.MongoClient c, String k)
    {
        var db    = c.GetServer().GetDatabase("db");
        var coll  = db.GetCollection(k);
        var query = Query <Entity> .EQ(e => e._id, k);

        var entity = coll.FindOne(query);
        var v      = entity.GetElement("data");

        //return read_string.invoke(v.Value.ToString());
        return(v.Value);
    }
Example #37
0
        public string GetAllVAData()
        {
            var client = new MongoDB.Driver.MongoClient("mongodb://anighthawks2.cloudapp.net:27017");
            var server = client.GetServer();
            var db     = server.GetDatabase("vaMongo");

            try
            {
                MongoCollection <BsonDocument> healthrecords = db.GetCollection <BsonDocument>("healthRecords");
                BsonDocument mongoDoc = healthrecords.FindOneAs <BsonDocument>();
                return(mongoDoc.ToJson());
            }
            catch
            {
                return(string.Empty);
            }
        }
Example #38
0
 public MongoDatabase(string _IPAddress, string _DatabaseName)
 {
     m_Client   = new MongoDB.Driver.MongoClient("mongodb://" + _IPAddress);
     m_Server   = m_Client.GetServer();
     m_Database = m_Server.GetDatabase(_DatabaseName);
 }
Example #39
0
        internal DbContext()
        {
            var client = new MongoDB.Driver.MongoClient(new MongoUrl("mongodb://data.octgn.net:27017"));

            Server = client.GetServer();
        }