Example #1
0
        //http://docs.mongodb.org/manual/core/aggregation-pipeline-optimization/#aggregation-pipeline-sequence-optimization

        public double Sum <T>(IMongoQuery query, IMongoGroupBy fieldsGroupBy)
        {
            var _match = query.ToMatchDocument();

            var _group = fieldsGroupBy.ToGroupDocument(MongoExtensions.GetCollectionName <T>());

            var _result = Aggregate <T>(_match, _group).SingleOrDefault();

            return(_result != null?Convert.ToDouble(_result.GetValue(1)) : 0);
        }
Example #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);
        }
Example #3
0
 /// <summary>
 /// Remove a collection type T in the database.
 /// </summary>
 public void Drop <T>()
 {
     Database.DropCollection(MongoExtensions.GetCollectionName <T>());
 }
Example #4
0
 public MongoCollection <T> GetCollection <T>()
 {
     return(Database.GetCollection <T>(MongoExtensions.GetCollectionName <T>()));
 }