I'm currently building a node/express.js app that uses mongoskin. I recently deployed my app to Heroku and having tons of headache with incorporating mongohq to work with my app.
This is the app.js file which I run with node app.js
var express = require("express");
var app = express();
decks = require('./routes/decks');
app.get('/decks', decks.findAll);
My package.json:
{
"name": "blah blah",
"description": "Why are there so my blah blah",
"version": "0.0.1",
"private": true,
"dependencies": {
"express": "3.x",
"mongodb": "1.1.8",
"socket.io": "0.9.10"
},
"engines": {
"node": "0.8.4",
"npm": "1.1.49"
}
}
After reading the guide on Heroku, I attempt to restructure decks.js and using mongoskin like so.
var mongo = require('mongoskin');
var mongoUri = process.env.MONGOHQ_URL;
var db = mongo.db(mongoUri);
exports.findById = function(req, res) {
var id = req.params.id;
console.log('Retrieving deck: ' + id);
db.collection('decks', function(err, collection) {
collection.findOne({'_id':new BSON.ObjectID(id)}, function(err, item) {
res.send(item);
});
});
};
However I've been getting the error:
Please ensure that you set the default write concern for the database by setting =
= one of the options =
= =
= w: (value of > -1 or the string 'majority'), where < 1 means =
= no write acknowlegement =
= journal: true/false, wait for flush to journal before acknowlegement =
= fsync: true/false, wait for flush to file system before acknowlegement =
= =
= For backward compatibility safe is still supported and =
= allows values of [true | false | {j:true} | {w:n, wtimeout:n} | {fsync:true}] =
= the default value is false which means the driver receives does not =
= return the information of the success/error of the insert/update/remove =
= =
= ex: new Db(new Server('localhost', 27017), {safe:false}) =
= =
= http://www.mongodb.org/display/DOCS/getLastError+Command =
= =
= The default of no acknowlegement will change in the very near future =
= =
= This message will disappear when the default safe is set on the driver Db =
========================================================================================
I've read tons of tutorials but I just cant' get my database working!! Please any help you be appreciated.
Your Db object is using a deprecated setting: "safe".
If you set the "w" option with the write concern you want, that error should go away.
Here's a link to the docs for instantiating that Db object.
http://mongodb.github.io/node-mongodb-native/api-generated/db.html
...
Oh, and you might try updating your uri variable to process.env.MONGOHQ_URL :P