public long GetCount(string collection, IDBQueryBuilder query) { IMongoCollection <BsonDocument> queryFilter = _mongoDataBase.GetCollection <BsonDocument>(collection); long result = queryFilter.Find(GetFilter(query.GetQuery())).Count(); return(result); }
public JArray Get(string collection, IDBQueryBuilder query, List <string> properties = null, Dictionary <string, int> sortColumns = null, int?top = default(int?), int?skip = default(int?)) { var findOptions = new FindOptions <BsonDocument>(); GetFilterProperty(properties, top, skip, findOptions); JObject sort = new JObject(); if (sortColumns != null) { foreach (var col in sortColumns) { sort[col.Key] = col.Value; } } findOptions.Sort = sort.ToString(); return(GetData(collection, query.GetQuery(), findOptions)); }
public JObject GetPageData(string collection, IDBQueryBuilder query, List <string> fields = null, Dictionary <string, int> sortColumns = null, int pageSize = 10, int currentPage = 1) { int?top = null; int?skip = null; top = pageSize; skip = (pageSize * (currentPage - 1)); var dbArrData = Get(collection, query, fields, sortColumns, top, skip); JObject extraData = new JObject(); long count = GetCount(collection, query); extraData[CommonConst.CommonField.TOTAL_RECORD_COUNT_KEY] = count; extraData[CommonConst.CommonField.TOTAL_PAGES_KEY] = Math.Ceiling(((double)count / pageSize)); extraData[CommonConst.CommonField.PAGE_SIZE_KEY] = pageSize; extraData[CommonConst.CommonField.CURRENT_PAGE_KEY] = currentPage; extraData[CommonConst.CommonField.DATA] = dbArrData; return(extraData); }
public long Update(string collection, IDBQueryBuilder query, JObject data, bool overrideData = false, MergeArrayHandling mergeType = MergeArrayHandling.Union) { throw new NotImplementedException(); }
public JObject GetPageData(string collection, IDBQueryBuilder query, List <string> fields = null, Dictionary <string, int> sortColumns = null, int pageSize = 10, int currentPage = 1) { throw new NotImplementedException(); }
public long GetCount(string collection, IDBQueryBuilder query) { throw new NotImplementedException(); }
public JArray Get(string collection, IDBQueryBuilder query, List <string> properties = null, Dictionary <string, int> sortColumns = null, int?top = null, int?skip = null) { throw new NotImplementedException(); }
public static JObject FirstOrDefault(this IDBService dbProxy, string collection, IDBQueryBuilder filterQuery, bool isOverrideCheck = false) { var response = dbProxy.Get(collection, filterQuery); if (response.Count != 0) { return(response[0] as JObject); } else { return(null); } }
public long Update(string collection, IDBQueryBuilder query, JObject data, bool overrideData = false, bool validateSchma = false, MergeArrayHandling mergeType = MergeArrayHandling.Union) { data[CommonConst.CommonField.UPDATED_DATE_TIME] = CommonUtility.GetUnixTimestamp(DateTime.Now); data[CommonConst.CommonField.UPDATED_BY] = GetUserId(); var dataResut = Get(collection, query, null, null); var dbcollection = _mongoDataBase.GetCollection <BsonDocument>(collection); if (overrideData) { if (dataResut.Count > 1) { throw new InvalidFilterException((int)ErrorCode.DB.MULTIPLE_ROW_RETURNED, string.Format("Update replace command cannot execute in multiple rows")); } if (dataResut.Count == 1) { (dataResut[0] as JObject).Merge(data, new JsonMergeSettings { MergeArrayHandling = mergeType }); if (data[CommonConst.CommonField.ID] != null) { dataResut[0][CommonConst.CommonField.ID] = data[CommonConst.CommonField.ID]; } BsonDocument document = MongoDB.Bson.Serialization.BsonSerializer.Deserialize <BsonDocument>(dataResut[0].ToString()); ReplaceOneResult result = dbcollection.ReplaceOne(GetFilter(query.GetQuery()), document, new UpdateOptions() { IsUpsert = true }); if (dataResut.Count != result.ModifiedCount) { throw new ClientValidationError((int)ErrorCode.DB.UPDATE_DATA_COUNT_NOT_MATCH, ErrorCode.DB.UPDATE_DATA_COUNT_NOT_MATCH.ToString(), null); } } else { WriteData(collection, data, validateSchma); return(1); } } else { foreach (var item in dataResut) { (item as JObject).Merge(data, new JsonMergeSettings { MergeArrayHandling = mergeType }); } foreach (var item in dataResut) { if (data[CommonConst.CommonField.ID] != null) { item[CommonConst.CommonField.ID] = data[CommonConst.CommonField.ID]; } BsonDocument document = MongoDB.Bson.Serialization.BsonSerializer.Deserialize <BsonDocument>(item.ToString()); // todo string filter = "{" + CommonConst.CommonField.DISPLAY_ID + " : '" + item[CommonConst.CommonField.DISPLAY_ID].ToString() + "'}"; ReplaceOneResult result = dbcollection.ReplaceOne(GetFilter(filter), document, new UpdateOptions() { IsUpsert = false }); } } return(dataResut.Count); }
public long Delete(string collection, IDBQueryBuilder query) { var result = _mongoDataBase.GetCollection <BsonDocument>(collection).DeleteMany(query.GetQuery()); return(result.DeletedCount); }