Пример #1
0
        public bool CheckIfDBExists(string dbName)
        {
            List <string> dbNames = _mongoDbClient.ListDatabaseNames().ToList();

            if (dbNames != null && dbNames.Count > 0 && dbNames.Where(x => x.ToLower() == dbName.ToLower()).Any())
            {
                return(true);
            }
            return(false);
        }
Пример #2
0
        private void SeedMongo()
        {
            if (_clientMongo.ListDatabaseNames().ToList().Any(nome => nome == _mongoDbConfiguracao.DatabaseName))
            {
                return;
            }

            ObtenhaColecao <Usuario>().InsertOne(new Usuario()
            {
                Login = "******",
                Senha = "talentosmaxima"
            });

            ObtenhaColecao <Produto>().InsertMany(new List <Produto>()
            {
                new Produto()
                {
                    Codigo        = "8689",
                    Nome          = "Fardo 6UN Coca-Cola 600ml",
                    PrecoUnitario = (decimal)17.34,
                    ImagemUrl     = "http://localhost:4200/assets/icones/foto-coca-cola.png"
                },
                new Produto()
                {
                    Codigo        = "8254",
                    Nome          = "Fardo 6UN Fanta 600ml",
                    PrecoUnitario = (decimal)16.64,
                    ImagemUrl     = "http://localhost:4200/assets/icones/foto-fanta.png"
                },
            });

            ObtenhaColecao <Cliente>().InsertMany(new List <Cliente>()
            {
                new Cliente()
                {
                    Codigo = "1",
                    Nome   = "Cliente 1"
                },
                new Cliente()
                {
                    Codigo = "2",
                    Nome   = "Cliente 2"
                },
                new Cliente()
                {
                    Codigo = "3",
                    Nome   = "Cliente 3"
                },
            });
        }
Пример #3
0
 public IAsyncCursor <string> ListDatabaseNames(
     CancellationToken cancellationToken = default(CancellationToken))
 {
     return(wrapped.ListDatabaseNames(cancellationToken));
 }
Пример #4
0
 public ActionResult <IEnumerable <string> > Get()
 {
     return(_mongoClient.ListDatabaseNames().ToList());
 }
Пример #5
0
 public IEnumerable <string> GetDatabases() =>
 _client.ListDatabaseNames().ToList();
Пример #6
0
        /// <summary>
        /// 异步获取mongo所有database
        /// </summary>
        /// <param name="connectionString">连接字符串,格式:mongodb://ip:port</param>
        /// <returns></returns>
        public static Task <List <string> > ListDataBasesAsync(string connectionString)
        {
            IMongoClient mongoClient = GetMongodbClient(connectionString);

            return(mongoClient.ListDatabaseNames().ToListAsync());
        }
Пример #7
0
 public IAsyncCursor <string> ListDatabaseNames(CancellationToken cancellationToken = default)
 {
     return(_client.ListDatabaseNames(cancellationToken));
 }
Пример #8
0
        private bool DoesDatabaseExist(string database)
        {
            var List = _client.ListDatabaseNames().ToList();

            return(List.Contains(database));
        }
Пример #9
0
 public async Task <List <string> > GetMongoCollections()
 {
     return(await _mongoClient.ListDatabaseNames().ToListAsync());
 }