title: Update in couchbase
body: <p>I need some help in update using couchbase. I have a task in my page. If the user clicks the like then the likes count should be updated in my couchbase bucket. I have tried my own update handler code but that has some time latency. I have included my update code too below. </p>
  
  <p>This is my code for liking a task...</p>
  
  <pre><code>public ResponseVO LikeTask(LikeVO likeVO)
          {
              ResponseVO response = new ResponseVO();
  
              try
              {
                  if (!isLiked(likeVO.TaskID, likeVO.UserID))
                  {
  
                      UpdateTaskDB likeUpdate = new UpdateTaskDB();
  
                      UpdateTaskVO updatetaskvo = new UpdateTaskVO();
                      updatetaskvo.FieldName = "Likes";
                      LikeVO tempvo = new LikeVO();
                      tempvo.LikedOn = DateTime.Now.ToString();
                      tempvo.UserID = likeVO.UserID;
                      tempvo.UserName = likeVO.UserName;
                      tempvo.TaskID = likeVO.TaskID;
                      updatetaskvo.ObjectValue = tempvo;
                      updatetaskvo.TaskID = likeVO.TaskID;
                      likeUpdate.UpdateDocument(updatetaskvo);
                }
                  response.StatusMessage = "Liked Successfully";
              }
              catch (Exception ex)
              {
                  response.StatusCode = "0";
                  response.StatusMessage = ex.Message;
              }
  
              return response;
          }
  </code></pre>
  
  <p>My own update handler code:</p>
  
  <pre><code> public class UpdateTaskDB
      {
          CouchbaseClient oCouchbase;
          public UpdateTaskDB()
          {
              oCouchbase = new CouchbaseClient("vwspace", "");
          }
          public TaskVO GetTaskByID(string task_id)
          {
  
              TaskVO results = null;
              try
              {
                  String str1;
  
                  str1 = (String)oCouchbase.Get(task_id);
  
                  results = JsonConvert.DeserializeObject&lt;TaskVO&gt;(str1);
              }
              catch (Exception ex)
              {
  
              }
              return results;
          }
  
          public void UpdateDocument(UpdateTaskVO inputParams)
          {
              try
              {
                  var client = new CouchbaseClient("vwspace", "");
                  TaskVO taskDoc = GetTaskByID(inputParams.TaskID);
  
                  switch (inputParams.FieldName)
                  {
                      case "Likes":
                          List&lt;LikeVO&gt; docLikes = taskDoc.likes;
                          docLikes.Add((LikeVO)inputParams.ObjectValue);
                          taskDoc.likes = docLikes;
                          break;
                      case "UnLike":
                          LikeVO unlikevo = (LikeVO)inputParams.ObjectValue;
                          for (int count = 0; count &lt; taskDoc.likes.Count; count++)
                          {
                              if (taskDoc.likes[count].UserID.Equals(unlikevo.UserID))
                              {
                                  unlikevo = taskDoc.likes[count];
                                  break;
                              }
                          }
                          taskDoc.likes.Remove(unlikevo);
                          break;
  
                      default:
                          break;
                  }
  
                  String json = JsonConvert.SerializeObject(taskDoc);
                  client.Store(StoreMode.Set, inputParams.TaskID, json);
  
              }
              catch (Exception ex)
              {
                  Console.Write("Exception :" + ex.Message);
              }
          }
      }
  </code></pre>
  
  <p>Is ther any other way to handle this update in couchbase? Kindly help me out..</p>