public string AddDocs ( string strDB, string strColl, string strData1, string strData2, string strData3, string strData4, string strData5, int strData6, AppConnection appConnection ) { string selecteddb = strDB; string selectedcoll = strColl; string fieldName = strData1; string fieldValue = strData2; string fieldName1 = strData3; string fieldValue1 = strData4; string fieldName2 = strData5; int fieldValue2 = strData6; IMongoDatabase db = appConnection.client1.GetDatabase(selecteddb); IMongoCollection <BsonDocument> collection = db.GetCollection <BsonDocument>(selectedcoll); var _doc = new BsonDocument { { fieldName, fieldValue }, { fieldName1, fieldValue1 }, { fieldName2, fieldValue2 } }; collection.InsertOne(_doc); return(Convert.ToString(_doc["_id"])); }
public void CreateDBs(string strDB, string strCollection, AppConnection appConnection, string strData1, string strData2) { string selecteddb = strDB; string selectedcoll = strCollection; IMongoDatabase db = appConnection.client1.GetDatabase(selecteddb); IMongoCollection <BsonDocument> collection = db.GetCollection <BsonDocument>(selectedcoll); BsonElement add = new BsonElement(strData1, strData2); BsonDocument doc = new BsonDocument(); doc.Add(add); collection.InsertOne(doc); BsonDocument findDoc = new BsonDocument(new BsonElement(strData1, strData2)); collection.FindOneAndDelete(findDoc); }
public void DeleteDocs ( string strDb, string strColl, string strObjc, AppConnection appConnection ) { string selecteddb = strDb; string selectedcoll = strColl; string objectId = strObjc; IMongoDatabase db = appConnection.client1.GetDatabase(selecteddb); IMongoCollection <BsonDocument> collection = db.GetCollection <BsonDocument>(selectedcoll); //delete by id var query = Builders <BsonDocument> .Filter.Eq("_id", new ObjectId(objectId)); var updateDoc = collection.DeleteOne(query); }
public void UpdateDocs ( string strDB, string strColl, string strData1, string strData2, string strData3, string strData4, string strData5, int strData6, string strObjc, AppConnection appConnection ) { string selecteddb = strDB; string selectedcoll = strColl; string fieldName = strData1; string fieldValue = strData2; string fieldName1 = strData3; string fieldValue1 = strData4; string fieldName2 = strData5; int fieldValue2 = strData6; string objectId = strObjc; IMongoDatabase db = appConnection.client1.GetDatabase(selecteddb); IMongoCollection <BsonDocument> collection = db.GetCollection <BsonDocument>(selectedcoll); BsonDocument findDoc = new BsonDocument { { fieldName, fieldValue }, { fieldName1, fieldValue1 }, { fieldName2, fieldValue2 } }; var query = Builders <BsonDocument> .Filter.Eq("_id", new ObjectId(strObjc)); var updateDoc = collection.FindOneAndReplace(query, findDoc); }