/// <summary>
        /// Returns the size of the result set (honors Skip and Limit, unlike Count which does not).
        /// </summary>
        /// <returns>The size of the result set.</returns>
        public virtual long Size()
        {
            _isFrozen = true;
            var args = new CountArgs
            {
                Query          = _query,
                Limit          = (_limit == 0) ? (int?)null : _limit,
                ReadPreference = _readPreference,
                Skip           = (_skip == 0) ? (int?)null : _skip
            };

            if (_options != null)
            {
                BsonValue hint;
                if (_options.TryGetValue("$hint", out hint))
                {
                    args.Hint = hint;
                }

                BsonValue maxTimeMS;
                if (_options.TryGetValue("$maxTimeMS", out maxTimeMS))
                {
                    args.MaxTime = TimeSpan.FromMilliseconds(maxTimeMS.ToDouble());
                }
            }
            return(_collection.Count(args));
        }
示例#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 args = new CountArgs
            {
                Collation      = _collation,
                Query          = _query,
                ReadPreference = _readPreference
            };

            if (_options != null)
            {
                BsonValue hint;
                if (_options.TryGetValue("$hint", out hint))
                {
                    args.Hint = hint;
                }

                BsonValue maxTimeMS;
                if (_options.TryGetValue("$maxTimeMS", out maxTimeMS))
                {
                    args.MaxTime = TimeSpan.FromMilliseconds(maxTimeMS.ToDouble());
                }
            }
            return(_collection.Count(args));
        }
        /// <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 args = new CountArgs {
                Query = _query
            };

            return(_collection.Count(args));
        }
        /// <summary>
        /// Returns the size of the result set (honors Skip and Limit, unlike Count which does not).
        /// </summary>
        /// <returns>The size of the result set.</returns>
        public virtual long Size()
        {
            _isFrozen = true;
            var args = new CountArgs
            {
                Query = _query,
                Limit = (_limit == 0) ? (int?)null : _limit,
                Skip  = (_skip == 0) ? (int?)null : _skip
            };

            return(_collection.Count(args));
        }
 public void TestCountWithMaxTime()
 {
     if (_primary.Supports(FeatureId.MaxTime))
     {
         using (var failpoint = new FailPoint(FailPointName.MaxTimeAlwaysTimeout, _server, _primary))
         {
             if (failpoint.IsSupported())
             {
                 failpoint.SetAlwaysOn();
                 var args = new CountArgs { MaxTime = TimeSpan.FromMilliseconds(1) };
                 Assert.Throws<ExecutionTimeoutException>(() => _collection.Count(args));
             }
         }
     }
 }