MongoDB.Driver.Mongo.Connect C# (CSharp) Метод

Connect() публичный Метод

public Connect ( ) : System.Boolean
Результат System.Boolean
        public Boolean Connect()
        {
            connection.Open();
            return connection.State == ConnectionState.Opened;
        }

Usage Example

        public IList<string> GetCollections(string server, string database, string port)
        {
            _db = new Mongo(string.Format("Server={0}:{1}", server, port));

            try
            {
                _db.Connect();
            }
            catch (SocketException ex)
            {
                throw new UnknownServerException(string.Format("Unknown server: {0}:{1}", server, port), ex);
            }

            IList<String> collectionNames = _db[database].GetCollectionNames();
            var filteredCollections = new List<string>();
            var hiddenCollectionCriteria = new string[] {"cubicle", "tmp.", ".$", "system.indexes"};

            foreach (string collectionName in collectionNames)
            {
                if (!hiddenCollectionCriteria.Any(criteria => collectionName.Contains(criteria)))
                {
                    int periodIndex = collectionName.IndexOf(".");
                    string collection = collectionName;

                    if (periodIndex >= 0 && periodIndex != (collectionName.Length - 1))
                        collection = collectionName.Substring(collectionName.IndexOf(".") + 1);

                    filteredCollections.Add(collection);
                }
            }

            return filteredCollections;
        }
All Usage Examples Of MongoDB.Driver.Mongo::Connect