private void StartDBChangeProcessQuick() { var result = new InvokeResult(); List <StorageData> updateList = new List <StorageData>(); var limitCount = Settings.DBSaveCountLimit; if (limitCount <= 0) { limitCount = 20; } if (UrlQueue.Instance.Count >= 10 && DBChangeQueue.Instance.Count <= limitCount) { return; } { var temp = DBChangeQueue.Instance.DeQueue(); if (temp != null) { var insertDoc = temp.Document; switch (temp.Type) { case StorageType.Insert: if (insertDoc.Contains("createDate") == false) { insertDoc.Add("createDate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //添加时,默认增加创建时间 } if (insertDoc.Contains("createUserId") == false) { insertDoc.Add("createUserId", "1"); } //更新用户 result = _mongoDBOp.Save(temp.Name, insertDoc);; break; case StorageType.Update: // insertDoc.Set("updateDate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //更新时间 // insertDoc.Set("updateUserId", "1"); result = _mongoDBOp.Save(temp.Name, temp.Query, insertDoc); break; case StorageType.Delete: result = _mongoDBOp.Delete(temp.Name, temp.Query); break; } //logInfo1.Info(""); if (result.Status == Status.Failed) { throw new Exception(result.Message); } } } if (DBChangeQueue.Instance.Count > 0) { StartDBChangeProcessQuick(); } }
/// <summary> /// 获取PKCount /// </summary> /// <param name="mongoDbOp"></param> /// <param name="tableName"></param> /// <param name="maxCount"></param> /// <returns></returns> public static void UpdateMaxCount(MongoOperation mongoDbOp, string tableName, int maxCount) { var maxMatCountObj = mongoDbOp.FindOne("TablePKCounter", Query.EQ("tbName", tableName)); if (maxMatCountObj != null) { var newObj = new BsonDocument().Add("count", maxCount); mongoDbOp.Save("TablePKCounter", Query.EQ("tbName", tableName), newObj); } else { var newObj = new BsonDocument().Add("tbName", tableName).Add("count", maxCount); mongoDbOp.Save("TablePKCounter", newObj); } }
/// <summary> /// 获取PKCount /// </summary> /// <param name="mongoDbOp"></param> /// <param name="tableName"></param> /// <returns></returns> public static int GetMaxCount(MongoOperation mongoDbOp, string tableName) { var maxMatCountObj = mongoDbOp.FindOne("TablePKCounter", Query.EQ("tbName", tableName)); if (maxMatCountObj != null) { return(maxMatCountObj.Int("count")); } else { var newObj = new BsonDocument().Add("tbName", tableName).Add("count", 1); var result = mongoDbOp.Save("TablePKCounter", newObj); return(2); } }
public ActionResult SaveCommenInfoTest(MutualData main, List <MutualData> subList) { JavaScriptSerializer jsonSerializer = new JavaScriptSerializer(); string abc = jsonSerializer.Serialize(HttpContext.Request.Form); string dddd = "{ \"name\" : \"123\", \"hijs\" : [{ \"id\" : 0, \"type\" : 1 }, { \"id\" : 1, \"type\" : 2 }, { \"id\" : 2, \"type\" : 3 }, { \"id\" : 3, \"type\" : 4 }] } "; string ccc = "{ 'name' : '123', 'hijs' : [{ 'id' : 0, 'type' : 1 }, { 'id' : 1, 'type' : 2 }, { 'id' : 2, 'type' : 3 }, { 'id' : 3, 'type' : 4 }] } "; MongoDB.Bson.IO.BsonReader bsonReader = MongoDB.Bson.IO.BsonReader.Create(ccc); BsonDocument tempBson = BsonDocument.ReadFrom(bsonReader); MongoOperation monOp = new MongoOperation(); monOp.Save("TestRelation", tempBson); return(View()); }