Exemplo n.º 1
0
        public ArrayList find(string db, string collection, int skip, int limit, int batch_size, Hashtable json_query, Hashtable json_fields)
        {
            var _db         = _mongoserver.GetDatabase(db);
            var _collection = _db.GetCollection <MongoDB.Bson.BsonDocument>(collection) as MongoDB.Driver.MongoCollection <MongoDB.Bson.BsonDocument>;

            MongoDB.Driver.QueryDocument _query = new MongoDB.Driver.QueryDocument(json_query);

            MongoDB.Driver.MongoCursor <MongoDB.Bson.BsonDocument> c = null;
            if (json_fields != null)
            {
                MongoDB.Driver.FieldsDocument _fields = new MongoDB.Driver.FieldsDocument(json_fields);
                c = _collection.FindAs <MongoDB.Bson.BsonDocument>(_query).SetSkip(skip).SetLimit(limit).SetBatchSize(batch_size).SetFields(_fields);
            }
            else
            {
                c = _collection.FindAs <MongoDB.Bson.BsonDocument>(_query).SetSkip(skip).SetLimit(limit).SetBatchSize(batch_size);
            }

            ArrayList _list = new ArrayList();

            foreach (var data in c)
            {
                var _data = data.ToHashtable();
                _data.Remove("_id");
                _list.Add(_data);
            }

            return(_list);
        }
Exemplo n.º 2
0
        public bool remove(Hashtable json_query)
        {
            MongoDB.Driver.QueryDocument _query = new MongoDB.Driver.QueryDocument(json_query);
            _collection.Remove(_query);

            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 根据ObjectID 查询
        /// </summary>
        public BsonDocument LogSelectOne(string objId)
        {
            BsonDocument docFind = new BsonDocument();

            MongoDB.Driver.MongoServer server = MongoDB.Driver.MongoServer.Create(ConfigurationManager.AppSettings["mongoDBConfig"]);
            server.Connect();
            //获取指定数据库
            MongoDB.Driver.MongoDatabase db = server.GetDatabase(ConfigurationManager.AppSettings["mongoDBName"].ToString());
            //获取表
            MongoDB.Driver.MongoCollection <BsonDocument> col = db.GetCollection <BsonDocument>(ConfigurationManager.AppSettings["mongoDBCollection"].ToString());

            try
            {
                var query = new MongoDB.Driver.QueryDocument("_id", new ObjectId(objId));
                docFind = col.FindOne(query);
            }
            catch (Exception ex)
            {
                log.Error(ex.ToString());
            }
            finally
            {
                server.Disconnect();
            }
            return(docFind);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 根据ObjectID 查询
        /// </summary>
        public BsonDocument LogSelectOne(string objId)
        {
            BsonDocument docFind = new BsonDocument();

            MongoDB.Driver.MongoServer server = MongoDB.Driver.MongoServer.Create(ConfigurationManager.AppSettings["mongoDBConfig"]);
            server.Connect();
            //获取指定数据库
            MongoDB.Driver.MongoDatabase db = server.GetDatabase(ConfigurationManager.AppSettings["mongoDBName"].ToString());
            string appid = string.Empty;

            if (!string.IsNullOrEmpty(txtAppid.Text.Trim()))
            {
                appid = txtAppid.Text.Trim().Split(' ')[0];
            }
            //获取表
            MongoDB.Driver.MongoCollection <BsonDocument> col = db.GetCollection <BsonDocument>(appid + "logs");

            try
            {
                var query = new MongoDB.Driver.QueryDocument("_id", new ObjectId(objId));
                docFind = col.FindOne(query);
            }
            catch (Exception ex)
            {
                log.Error(ex.ToString());
            }
            finally
            {
                server.Disconnect();
            }
            return(docFind);
        }
Exemplo n.º 5
0
        public bool update(Hashtable json_query, Hashtable json_update)
        {
            MongoDB.Driver.QueryDocument  _query  = new MongoDB.Driver.QueryDocument(json_query);
            MongoDB.Driver.UpdateDocument _update = new MongoDB.Driver.UpdateDocument(json_update);

            var ret = _collection.Update(_query, _update);

            return(true);
        }
Exemplo n.º 6
0
        public bool remove(string db, string collection, Hashtable json_query)
        {
            var _db         = _mongoserver.GetDatabase(db);
            var _collection = _db.GetCollection <MongoDB.Bson.BsonDocument>(collection) as MongoDB.Driver.MongoCollection <MongoDB.Bson.BsonDocument>;

            MongoDB.Driver.QueryDocument _query = new MongoDB.Driver.QueryDocument(json_query);
            _collection.Remove(_query);

            return(true);
        }
Exemplo n.º 7
0
        public bool update(string db, string collection, Hashtable json_query, Hashtable json_update)
        {
            var _db         = _mongoserver.GetDatabase(db);
            var _collection = _db.GetCollection <MongoDB.Bson.BsonDocument>(collection) as MongoDB.Driver.MongoCollection <MongoDB.Bson.BsonDocument>;

            MongoDB.Driver.QueryDocument  _query  = new MongoDB.Driver.QueryDocument(json_query);
            MongoDB.Driver.UpdateDocument _update = new MongoDB.Driver.UpdateDocument(json_update);

            var ret = _collection.Update(_query, _update);

            return(true);
        }
Exemplo n.º 8
0
        public bool remove(string db, string collection, Hashtable json_query)
        {
            var _db         = _mongoserver.GetDatabase(db);
            var _collection = _db.GetCollection <MongoDB.Bson.BsonDocument>(collection) as MongoDB.Driver.MongoCollection <MongoDB.Bson.BsonDocument>;

            MongoDB.Driver.QueryDocument _query = new MongoDB.Driver.QueryDocument(json_query);
            var ret = _collection.Remove(_query);

            if (ret != null && ret.HasLastErrorMessage)
            {
                log.log.operation(new System.Diagnostics.StackFrame(), service.timerservice.Tick, ret.LastErrorMessage);
            }

            return(true);
        }
Exemplo n.º 9
0
        public ArrayList find(int skip, int limit, int batch_size, Hashtable json_query, Hashtable json_fields)
        {
            MongoDB.Driver.QueryDocument  _query  = new MongoDB.Driver.QueryDocument(json_query);
            MongoDB.Driver.FieldsDocument _fields = new MongoDB.Driver.FieldsDocument(json_fields);

            var c = _collection.FindAs <MongoDB.Bson.BsonDocument>(_query).SetSkip(skip).SetLimit(limit).SetBatchSize(batch_size).SetFields(_fields);

            ArrayList _list = new ArrayList();

            foreach (var data in c)
            {
                _list.Add(data.ToHashtable());
            }

            return(_list);
        }