public MongoCursor <BsonDocument> Query(string collection) { MongoDB.Driver.MongoCollection mongoCollection = getMongoCollection(collection); MongoCursor <BsonDocument> cursor; cursor = mongoCollection.FindAllAs <BsonDocument>(); return(cursor); }
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); }
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); }
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); }
//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); }
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); }