public DataModel Update(DataModel model) { var resultModel = new DataModel() { operationSuccesfull = false }; var originalDoc = GetBsonDoc(model); if (originalDoc != null) { var replacementDoc = originalDoc.Merge(model.getBsonModel(), true); var replacementResult = getMongoCollection(model).ReplaceOne(model.getOrFilter(), replacementDoc); if (replacementResult.ModifiedCount == 1) { resultModel.operationSuccesfull = true; replacementDoc.Remove("_id"); resultModel.jsonModel = replacementDoc.ToJson(new JsonWriterSettings { OutputMode = JsonOutputMode.Strict }); } } return resultModel; }
public DataModel Insert(DataModel model) { getMongoCollection(model).InsertOne(model.getBsonModel()); return new DataModel() { operationSuccesfull = true , jsonModel = model.jsonModel }; }