Пример #1
0
        public static BsonDocument ToGroupDocument <T>(this IMongoFields fields)
        {
            var _coll = GetCollectionName <T>();

            var _sums = new BsonDocument {
                { "_id", new BsonDocument(_coll, string.Format("${0}", _coll)) }
            };

            foreach (string _name in fields.ToBsonDocument().Names)
            {
                _sums.Add(_name, new BsonDocument("$sum", string.Format("${0}", _name)));
            }

            return(new BsonDocument("$group", _sums));
        }
Пример #2
0
        public CommandResult FullTextSearch <T>(string lang, string keyword, IMongoQuery query, IMongoFields fields, int limit)
        {
            var _cmd = new CommandDocument
            {
                { "text", MongoExtensions.GetCollectionName <T>() },
                { "language", lang },
                { "search", (keyword != "") ? keyword : "" },
                { "filter", query.ToBsonDocument() },
                { "project", fields.ToBsonDocument() },
                { "limit", limit }
            };


            var _result = Database.RunCommand(_cmd);

            return(_result);
        }
Пример #3
0
        private FindAndModifyResult FindAndModifyImpl(IMongoQuery query, IMongoSortBy sortBy, bool remove, IMongoUpdate update, bool returnNew, IMongoFields fields, bool upsert)
        {
            var sw = new Stopwatch();

            sw.Start();
            var result = base.FindAndModify(query, sortBy, update, fields, returnNew, upsert);

            sw.Stop();

            var commandStringBuilder = new StringBuilder(1024);

            commandStringBuilder.AppendFormat("db.{0}.findAndModify(query, sort, remove, update, new, fields, upsert)", Name);

            if (query != null)
            {
                commandStringBuilder.AppendFormat("\nquery = {0}", query.ToBsonDocument());
            }
            else
            {
                commandStringBuilder.Append("\nquery = null");
            }

            if (sortBy != null)
            {
                commandStringBuilder.AppendFormat("\nsort = {0}", sortBy.ToBsonDocument());
            }
            else
            {
                commandStringBuilder.Append("\nsort = null");
            }

            commandStringBuilder.AppendFormat("\nremove = {0}", remove ? "true" : "false");

            if (update != null)
            {
                commandStringBuilder.AppendFormat("\nupdate = {0}", update.ToBsonDocument());
            }
            else
            {
                commandStringBuilder.Append("\nupdate = null");
            }

            commandStringBuilder.AppendFormat("\nnew = {0}", returnNew ? "true" : "false");

            if (fields != null)
            {
                commandStringBuilder.AppendFormat("\nfields = {0}", fields.ToBsonDocument());
            }
            else
            {
                commandStringBuilder.Append("\nfields = null");
            }

            commandStringBuilder.AppendFormat("\nupsert = {0}", upsert ? "true" : "false");

            string commandString = commandStringBuilder.ToString();

            ProfilerUtils.AddMongoTiming(commandString, sw.ElapsedMilliseconds, ExecuteType.Update);

            return(result);
        }