Beispiel #1
0
        public MongoCursor <BsonDocument> Query(string collection)
        {
            MongoDB.Driver.MongoCollection mongoCollection = getMongoCollection(collection);
            MongoCursor <BsonDocument>     cursor;

            cursor = mongoCollection.FindAllAs <BsonDocument>();
            return(cursor);
        }
Beispiel #2
0
 private MongoDB.Driver.MongoCollection getMongoCollection(string collection)
 {
     MongoDB.Driver.MongoDatabase mongoDataBase = getMongoServer();
     if (!mongoDataBase.CollectionExists(collection))
     {
         mongoDataBase.CreateCollection(collection);
     }
     MongoDB.Driver.MongoCollection mongoCollection = mongoDataBase.GetCollection(collection);//选择集合,相当于表
     return(mongoCollection);
 }
Beispiel #3
0
        public string Insert(string collection, Object document)
        {
            string result = "";

            try
            {
                MongoDB.Driver.MongoCollection mongoCollection = getMongoCollection(collection);
                mongoCollection.Insert(document);
                mongoCollection.Database.Server.Disconnect();
            }
            catch (Exception e)
            {
                result = e.Message;
            }

            return(result);
        }
Beispiel #4
0
        public MongoCursor <T> Query(string collection, QueryDocument query)
        {
            MongoCursor <T> m = null;

            try
            {
                MongoDB.Driver.MongoCollection mongoCollection = getMongoCollection(collection);

                m = mongoCollection.FindAs <T>(query);
                mongoCollection.Database.Server.Disconnect();
            }
            catch
            {
                //记录日志信息
            }
            return(m);
        }
Beispiel #5
0
        //public string Delete(string collection, string meterNo)
        //{
        //    string result = "";
        //    try
        //    {
        //        MongoDB.Driver.MongoCollection mongoCollection = getMongoCollection(collection);
        //        var query = new QueryDocument();
        //        query.Add("MeterNo", meterNo);
        //        mongoCollection.Remove(query);

        //        mongoCollection.Database.Server.Disconnect();
        //    }
        //    catch (Exception e)
        //    {
        //        result = e.Message;
        //    }

        //    return result;
        //}


        public string Delete(string collection, IMongoQuery query)
        {
            string result = "";

            try
            {
                MongoDB.Driver.MongoCollection mongoCollection = getMongoCollection(collection);
                mongoCollection.Remove(query);
                mongoCollection.Database.Server.Disconnect();
            }
            catch (Exception e)
            {
                result = e.Message;
            }

            return(result);
        }
Beispiel #6
0
        public string Update(string collection, IMongoQuery query, IMongoUpdate update)
        {
            string result = "";

            try
            {
                MongoDB.Driver.MongoCollection mongoCollection = getMongoCollection(collection);
                mongoCollection.Update(query, update);

                //mongoCollection.DropIndex (

                mongoCollection.Database.Server.Disconnect();
            }
            catch (Exception e)
            {
                result = e.Message;
            }

            return(result);
        }
        // public InsertRecordRetro InsertRecordRetro;
       // private readonly SetupController _setupController;

        //Constructor
        public DesktopWebController()
        {
            Trace.TraceInformation("Entering DesktopWebController constructor...");
            MyMongoCollection = SetupController.GetNewCollectionIfNotExist(WebToMongoTypes.WEB);
            _mongoDataAccess = new MongoDataAccess();
        }
        //private readonly MongoDataAccess _mongoDataAccess;

        // public InsertRecordRetro InsertRecordRetro;
       // private readonly SetupController _setupController;

        //Constructor
        public MobileWebController()
        {
            Trace.TraceInformation("Entering MobileController contructor...");
            MyMongoCollection = SetupController.GetNewCollectionIfNotExist(WebToMongoTypes.MOBILE);
          
        }