lundi 30 mars 2015

How do I install, and connect to mongodb in node.js on my remote server (ubuntu)?

I have spent at least 3 hours failing to connect to mongodb onto my server. I have managed to install it, create my database, and i have created a new user in the console:



use admin


then



db.createUser(
{
user: "admin",
pwd: "xxx",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
}
)


And all seems good. Then, to connect to the user in app.js, i do:



var databaseUrl = "mongodb://admin:xxx@108.61.221.63:27018/mydatabasename";
var db = require("mongodb").connect(databaseUrl);


At this point, when i run the server (npm start) this is what i get:



{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version
{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version
{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version
{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version
/home/adminftp/public_html/globular/node_modules/mongodb/lib/mongo_client.js:92
throw new Error("no callback function provided");
^
Error: no callback function provided
at Function.MongoClient.connect (/home/adminftp/public_html/globular/node_modules/mongodb/lib/mongo_client.js:92:11)
at Object.<anonymous> (/home/adminftp/public_html/globular/app.js:31:29)
at Module._compile (module.js:462:26)
at Object.Module._extensions..js (module.js:480:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:503:10)
at startup (node.js:132:16)
at node.js:817:3


...i have no idea what to make of it.


If anyone has any ideas how i can resolve it i would appreciate it. Thank you!


Aucun commentaire:

Enregistrer un commentaire