/// <summary>
        /// Note:  Before/After Save does not get called with this method.
        /// Find and Update FIRST matching document
        /// </summary>
        /// <param name="query"></param>
        /// <param name="sort"></param>
        /// <param name="update"></param>
        /// <param name="returnNew"></param>
        /// <param name="upsert"></param>
        /// <returns></returns>
        public FindAndModifyResult FindAndUpdate(IMongoQuery query, IMongoSortBy sort, IMongoUpdate update, bool returnNew, bool upsert)
        {
            //Implement necessary logic here (e.g.  auditing)
            IMongoQuery fixedQuery = MongoUtil.FormatIdElementForMongoQuery(query);

            return(Collection.FindAndModify(fixedQuery, sort, update, returnNew, upsert));
        }
        public WriteConcernResult Update(IMongoQuery query, UpdateBuilder update, UpdateFlags updateFlags, WriteConcern writeConcern)
        {
            //TODO:  paul, deal with auditing
            IMongoQuery fixedQuery = MongoUtil.FormatIdElementForMongoQuery(query);

            return(Collection.Update(query, update, updateFlags, writeConcern));
        }
        public MongoCursor <T> Find(IMongoQuery query, params string[] propertiesToReturn)
        {
            IMongoQuery fixedQuery = MongoUtil.FormatIdElementForMongoQuery(query);
            var         cursor     = Collection.Find(fixedQuery);

            cursor.SetFields(propertiesToReturn);

            return(cursor);
        }
        public IEnumerable <string> Distinct(string key, IMongoQuery query)
        {
            IMongoQuery fixedQuery = MongoUtil.FormatIdElementForMongoQuery(query);

            var results = Collection.Distinct(key, fixedQuery);

            return(results.Where(x => x != BsonNull.Value)
                   .Select(x => x.ToString()));
        }
        public MongoCursor <Y> FindAs <Y>(IMongoQuery query)
        {
            IMongoQuery fixedQuery = MongoUtil.FormatIdElementForMongoQuery(query);

            return(Collection.FindAs <Y>(fixedQuery));
        }
        public MongoCursor FindAsBsonDocument(IMongoQuery query)
        {
            IMongoQuery fixedQuery = MongoUtil.FormatIdElementForMongoQuery(query);

            return(Collection.FindAs <BsonDocument>(fixedQuery));
        }
        /// <summary>
        /// Note:  Before/After delete do not get called with this method
        /// </summary>
        /// <param name="query"></param>
        /// <param name="writeConcern"></param>
        /// <returns></returns>
        public WriteConcernResult Remove(IMongoQuery query, WriteConcern writeConcern)
        {
            IMongoQuery fixedQuery = MongoUtil.FormatIdElementForMongoQuery(query);

            return(Collection.Remove(fixedQuery, writeConcern));
        }
        public MapReduceResult MapReduce(IMongoQuery query, BsonJavaScript map, BsonJavaScript reduce, IMongoMapReduceOptions options)
        {
            IMongoQuery fixedQuery = MongoUtil.FormatIdElementForMongoQuery(query);

            return(Collection.MapReduce(fixedQuery, map, reduce, options));
        }
        public IEnumerable <BsonDocument> Group(IMongoQuery query, string key, BsonDocument initial, BsonJavaScript reduce, BsonJavaScript finalize)
        {
            IMongoQuery fixedQuery = MongoUtil.FormatIdElementForMongoQuery(query);

            return(Collection.Group(fixedQuery, key, initial, reduce, finalize));
        }
        public T FindOne(IMongoQuery query)
        {
            IMongoQuery fixedQuery = MongoUtil.FormatIdElementForMongoQuery(query);

            return(Collection.FindOne(fixedQuery));
        }
        /// <summary>
        ////Find and remove the FIRST item found.
        /// Note:  Before and After Delete do not get called with this method.
        /// </summary>
        /// <param name="query"></param>
        /// <param name="sort"></param>
        /// <returns></returns>
        public FindAndModifyResult FindAndRemove(IMongoQuery query, IMongoSortBy sort)
        {
            IMongoQuery fixedQuery = MongoUtil.FormatIdElementForMongoQuery(query);

            return(Collection.FindAndRemove(fixedQuery, sort));
        }