Updating docs faster



Hello everyone,

I have a problem with updating my docs in the bucket. When I change something, like, add a new property to my docs such as “surname”: “blahblah”, it takes a very long time to update all the documents even though all it has to do is add a single line. Is it normal or am I doing something wrong? I’m using Upsert method to do so. What can I do to make it faster? This is my method :

 public static void sendToCouchbase()
            var newDoc = new Document<Forum>();
            var documents = getTables();
            var myBucket = myCluster.OpenBucket();

            for (int i = 0; i < documents.Count; i++)
                using (myBucket = myCluster.OpenBucket())


                    newDoc.Content = documents[i];

                    newDoc.Id = documents[i].Type + "_" + documents[i].Id;

                    var result = myBucket.Upsert(newDoc);






@HandeBc -

The problem is that your creating a new bucket object (and disposing it) on every iteration. I would switch to using the ClusterHelper or at the least move the opening of the bucket outside the for loop.

In general, you should create one Cluster object and one (or more buckets by name) per application and reuse them over and over again. You can declare them statically in your Global.asax or anywhere so that they will not go out of scope.



Try using the N1QL UPDATE statement. To add a new field, you simply need to set the value for that.

UPDATE mystuff SET mykey = “myvalue”;


@jmorris Thanks, totally worked!