Exemple #1
0
        /// <summary>
        /// Returns the number of documents that match the query (ignores Skip and Limit, unlike Size which honors them).
        /// </summary>
        /// <returns>The number of documents that match the query.</returns>
        public virtual int Count()
        {
            isFrozen = true;
            var command = new CommandDocument {
                { "count", collection.Name },
                { "query", BsonDocumentWrapper.Create(query) } // query is optional
            };
            var result = database.RunCommand(command);

            return(result.Response["n"].ToInt32());
        }
Exemple #2
0
        /// <summary>
        /// Returns the number of documents that match the query (ignores Skip and Limit, unlike Size which honors them).
        /// </summary>
        /// <returns>The number of documents that match the query.</returns>
        public virtual long Count()
        {
            _isFrozen = true;
            var command = new CommandDocument
            {
                { "count", _collection.Name },
                { "query", BsonDocumentWrapper.Create(_query), _query != null } // query is optional
            };
            var result = _database.RunCommand(command);

            return(result.Response["n"].ToInt64());
        }
Exemple #3
0
        /// <summary>
        /// Drops a database.
        /// </summary>
        /// <param name="databaseName">The name of the database to be dropped.</param>
        /// <returns>A <see cref="CommandResult"/>.</returns>
        public virtual CommandResult DropDatabase(
            string databaseName
            )
        {
            MongoDatabase database = GetDatabase(databaseName);
            var           command  = new CommandDocument("dropDatabase", 1);

            return(database.RunCommand(command));
        }
        /// <summary>
        /// Drops a database.
        /// </summary>
        /// <param name="databaseName">The name of the database to be dropped.</param>
        /// <param name="credentials">Credentials for the database to be dropped (or admin credentials).</param>
        /// <returns>A <see cref="CommandResult"/>.</returns>
        public virtual CommandResult DropDatabase(string databaseName, MongoCredentials credentials)
        {
            MongoDatabase database = GetDatabase(databaseName, credentials);
            var           command  = new CommandDocument("dropDatabase", 1);
            var           result   = database.RunCommand(command);

            _indexCache.Reset(databaseName);
            return(result);
        }