[英]Trouble deploying to Heroku using Mongoskin and MongoHQ with Nodejs
我目前正在構建一個使用mongoskin的node / express.js應用程序。 我最近將我的應用程序部署到了Heroku,並且由於將mongohq與我的應用程序結合使用而感到頭疼。
這是我與節點app.js一起運行的app.js文件
var express = require("express");
var app = express();
decks = require('./routes/decks');
app.get('/decks', decks.findAll);
我的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"
}
}
閱讀了有關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);
});
});
};
但是我一直在得到錯誤:
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 =
========================================================================================
我讀了很多教程,但是我無法使數據庫正常工作! 請任何幫助,您將不勝感激。
您的Db對象正在使用不建議使用的設置:“安全”。
如果將“ w”選項設置為所需的寫關注點,則該錯誤應消失。
這是用於實例化該Db對象的文檔的鏈接。
http://mongodb.github.io/node-mongodb-native/api-generation/db.html
...
哦,您可以嘗試將uri變量更新為process.env.MONGOHQ_URL:P
社長說的對
修改此行:
var db = mongo.db(mongoUri);
對此:
var db = mongo.db(mongoUri, {w:1});
這將使您在對數據庫執行操作時寫確認,並使錯誤消失
有關寫問題的更多信息,請查看此鏈接
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.