Sergei Basharov
Sergei Basharov

Reputation: 53850

Close Couchbase connection once entries have been saved

I use Faker to insert some dummy data into Couchbase database. It seems to me that I need to close the connection on the insertion operations complete because now when it inserts all the entries, the app keeps being active, doesn't return me to console. How to manage it?

Upvotes: 3

Views: 1512

Answers (3)

jbll
jbll

Reputation: 1216

Here's an updated example snippet for 2.x versions of the Node Couchbase SDK that uses disconnect(). Idea is that when you're done with all your operations on a connection, shut it down:

var bucket = myCluster.openBucket(bucketName, function (err) {
    if (err) {/*handle error*/}
    bucket.get(someId, function (err, res) {
        bucket.disconnect();
        //do stuff with results
    });
});

Upvotes: 1

m03geek
m03geek

Reputation: 2538

To close connection to bucket you can use bucket.shutdown() function. See example below:

couchbase.connect(config, function(err, bucket) {
  ... // do some work
  bucket.shutdown(); // shutdown connection on work done
});

Link to test for this function on github.

Upvotes: 5

Adam
Adam

Reputation: 1099

One way would be:

process.exit();

which can get you out of the process.

I do not know about the couchbase module specifically.

Upvotes: 0

Related Questions