简体   繁体   English

使用Mongoskin和MongoHQ和Node.js部署到Heroku时遇到问题

[英]Trouble deploying to Heroku using Mongoskin and MongoHQ with Nodejs

I'm currently building a node/express.js app that uses mongoskin. 我目前正在构建一个使用mongoskin的node / express.js应用程序。 I recently deployed my app to Heroku and having tons of headache with incorporating mongohq to work with my app. 我最近将我的应用程序部署到了Heroku,并且由于将mongohq与我的应用程序结合使用而感到头疼。

This is the app.js file which I run with node app.js 这是我与节点app.js一起运行的app.js文件

var express = require("express");
var app = express();
decks = require('./routes/decks');
app.get('/decks', decks.findAll);

My package.json: 我的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. 阅读了有关Heroku的指南后,我尝试重新构建decks.js并像这样使用mongoskin。

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". 您的Db对象正在使用不建议使用的设置:“安全”。

If you set the "w" option with the write concern you want, that error should go away. 如果将“ w”选项设置为所需的写关注点,则该错误应消失。

Here's a link to the docs for instantiating that Db object. 这是用于实例化该Db对象的文档的链接。

http://mongodb.github.io/node-mongodb-native/api-generated/db.html http://mongodb.github.io/node-mongodb-native/api-generation/db.html

... ...

Oh, and you might try updating your uri variable to process.env.MONGOHQ_URL :P 哦,您可以尝试将uri变量更新为process.env.MONGOHQ_URL:P

what supershabam said was right 社长说的对

modify this line: 修改此行:

var db = mongo.db(mongoUri);

to this: 对此:

var db = mongo.db(mongoUri, {w:1});

this will give you write acknowledgements when performing operations on the database, and make the error go away 这将使您在对数据库执行操作时写确认,并使错误消失

for more information on write concerns, check this link out 有关写问题的更多信息,请查看此链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM