Couchbase node.js module - node.js

I am using node v.0.10.33 couchbase, node module v.2.0.0 and couchbase-server-v.3.0.1
var couchbase = require("couchbase");
// Connect to Couchbase Server
var cluster = new couchbase.Cluster('10.50.10.31:8091');
var bucket = cluster.openBucket('beer-sample', function(err) {
if (err) {
// Failed to make a connection to the Couchbase cluster.
throw err;
}
// Retrieve a document
bucket.get('aass_brewery-juleol', function(err, result) {
if (err) {
// Failed to retrieve key
throw err;
}
var doc = result.value;
console.log(doc.name + ', ABV: ' + doc.abv);
// Store a document
doc.comment = "Random beer from Norway";
bucket.replace('aass_brewery-juleol', doc, function(err, result) {
if (err) {
// Failed to replace key
throw err;
}
console.log(result);
// Success!
process.exit(0);
});
});
});
when i run the above program on the same machine in which couchbase server is installed its working fine..
with this line
var cluster = new couchbase.Cluster('127.0.0.1:8091');
But when i run with another system which connected through Local area network I am getting network error. with this line
var cluster = new couchbase.Cluster('10.50.10.31:8091');
this error...
Couchbase Error : Network Failure
also tried
var cluster = new couchbase.Cluster('couchbase://10.50.10.31')
not working...
var cluster = new couchbase.Cluster('couchbase://localhost')
working fine...
Where i am going wrong please help me...
sorry for mistakes.

As per Couchbase Node.js SDK documentation, try creating connection like this:
var couchbase = require("couchbase");
var bucket = new couchbase.Connection({
'bucket':'beer-sample',
'host':'10.50.10.31:8091'
}, function(err) {
if (err) {
// Failed to make a connection to the Couchbase cluster.
throw err;
}
// your code to work with bucket here...
});

The problem is with python and node-gyp
i have upgraded python
and rebuild the couchbase module
cd path_to_nodejs_project/node_modules/coucbase/
node-gyp clean
node-gyp configure
node-gyp build
This solved my problem

Related

Electron/NodeJS Connecting to SQL Server using mssql not working

I'm new to Electron and trying to make 1 st application in which I need to connect it to a SQL server database for data storing/retrieving. I've have installed this plugin (https://www.npmjs.com/package/mssql#connect-callback) and followed their instructions but got no success regarding the connection. The weird part is that I also get no error or whatever showing in the console so I'm totally lost. Any help would be much appreciated, thank you guys.
Ps: I'm sure that there's no problem with the database since I can still connect to it using the same config setting below with a database client manager tool.
Below is the code I've used for simple testing connection.
<script type="text/javascript">
$(document).ready(function () {
const electron = require('electron');
const sql = require('mssql');
const config = {
user: 'ql*****',
password: 'qlh****',
server: '123.20.****',
database: 'QLHS'
};
async () => {
try {
await sql.connect(config);
const result = await sql.query`select * from DM_DONVI`;
console.dir(result);
} catch (err) {
console.log(err);
}
};
});
</script>
The link you provided is working. I tried the same. The error log can be seen in view->Toogle Developer Tools. The issue is you need install mysql.
npm install mysql --save
Then the code works fine.
Thank you Mr :D Actually, the thing that didn't work in my original post is the async part. Changing that to this and everything is fine now:
sql.connect(config, function (err) {
if (err) console.log(err);
var request = new sql.Request();
request.query('select * from DM_DONVI', function (err, recordset) {
if (err) {
console.log("Something went wrong")
}
else {
var result = JSON.stringify(recordset);
console.log(recordset.recordsets[0]);
}
});
});

How to install NodeJS + MongoDB on ec2 Amazon server

I don't have much knowledge about mongo and NodeJS, and also about server set up so I might be asking something basic.
I'm trying to install MongoDB and NodeJS for school project.
In order to do so I registered to Amazon EC2 server and implemented an instance according to some tutorials I've found on line.
Using MongoDB wiki, I've installed Mongo on the server and using another Tutorial I installed NodeJS.
Just to be super clear, please see below picture who's showing the directory and MongoDB server listening:
http://s23.postimg.org/k02f747m2/mongo_Dir.jpg
After I've done that I'm trying to start using the server, I've created a simple file using the following code:
var mongodb = require('mongodb');
var server = new mongodb.Server('127.0.0.1', 27017, {});
var client = new mongodb.Db('exampledb', server, {w: 1});
client.open(function(err) {
if (err) throw err;
client.collection('students', function(err, collection) {
if (err) throw err;
collection.insert(
{
"name": "Noam",
"year": "2012."
},
{safe: true},
function(err, documents) {
if (err) throw err;
console.log('Document ID is: ' + documents[0]._id);
}
);
});
});
Now I tried to run the file and received the following error
http://s30.postimg.org/sqplfazlt/eror.jpg
Any help?

Failed to open a bucket, anyone can tell me why?

var couchbase = require("couchbase");
var cluster = new couchbase.Cluster('127.0.0.1:8091');
var bucket = cluster.openBucket('LFC', function(err) {
if (err) {
throw err;
}
console.log('Success')
});
Here how i connect to the bucket but when i try to open the server it says : "Failed to connect to the bucket".
First of all change this line with:
var cluster = new couchbase.Cluster('couchbase://localhost:8091');
Then try to uninstall couchbase , erase everything and install again. If you haven't created the bucket 'LFC' first create it from console. Then run your code.

Problems Deploying a Node.js app on Heroku Using MongoLab

I'm attempting to deploy a very simple app to Heroku. The code for the application can be found on Ray Wenderlich's site, here: http://www.raywenderlich.com/61078/write-simple-node-jsmongodb-web-service-ios-app I keep getting the same error whenever I try to have Heroku compile the code...
var mongoHost = "mongodb://username:password#ds041140.mongolab.com:41140/heroku_app23491233";
var mongoPort = 41140;
var collectionDriver;
var mongoClient = new MongoClient(new Server(mongoHost, mongoPort)); //B
mongoClient.open(function(err, mongoClient) { //C
if (!mongoClient) {
console.error("Error! Exiting... Must start MongoDB first");
process.exit(1); //D
}
var db = mongoClient.db("heroku_app23491233"); // E
collectionDriver = new CollectionDriver(db); //F
});
When I type heroku logs, the error I get comes from if (!mongoClient) above...
app[web.1]: Error! Exiting... Must start MongoDB first
I'm sure the problem lies somewhere in my attempt to connect to the MongoLab database. I've copied the URI from MongoLab and I've created a user with the proper credentials.
I can connect to localhost just fine with very similar code, so I'm not sure what is going wrong in this example.
Thank you.
Based on the docs, my best guess is that it's because the Server constructor expects the first argument to contain only the host name (in the case of your MongoLab, ds041140.mongolab.com). However, I think you can pass your connection string into MongoClient.connect:
// Make sure to replace username and password with the proper values.
var mongoHost = "mongodb://username:password#ds041140.mongolab.com:41140/heroku_app23491233";
MongoClient.connect(mongoHost, function(err, db) {
if (err) return console.log(err);
db.collection('mongoclient_test').update({a:1}, {b:1}, {upsert:true}, function(err, result) {
db.close();
if (err) return console.log(err);
console.log('Okay', result);
});
});
Documentation Page For MongoClient
Hopefully that helps!

Couchbase get / getMulti fails on timeout in node.js

I'm new with Couchbase and trying to use the couchbase module 1.2.1, the connection to the DB seems to work fine, but the get and getMulti operations are failing and the error I'm getting is "Operation timed out".
I tried to increase the timeout, but it didn't help.
var db = new couchbase.Connection({ host:'localhost:8091', bucket:'beer-sample'},
function(err){
if (err){
throw err; // not getting here
}
});
db.get("id", function(err, result) {
if (!err && result){ // getting error
req.id = result;
}
});
What can be the problem?
You should try to reinstall Couchbase Server and try again using a host of 127.0.0.1:8091.
What version of Couchbase Server, and what platform/architecture you are using would also be helpful to know.

Resources