0

これを理解しようとしています。とても混乱している/イライラしている

[サーバー 1] は私のアプリ サーバーです。その中に住んでいます:

app.js

var mongoose = require('mongoose'),
    express = require("express"),
    app = express();

mongoose.connect('mongodb://mongo:mymongopass@[SERVER 2 IP]'); 

app.configure(function () {
    app.use(express.bodyParser());
    app.use(express.methodOverride());
    app.use(app.router);
});


app.get('/', function (req, res) {
    console.log('hi');
    res.send('hello world');
});

// auctions api
var auctions = require('./auctions.js');
app.get('/auctions', auctions.list);
app.get('/auctions/create', auctions.create);

app.listen(3000);

auctions.js

// load up the model
var Auction = require('./models/auction.js');


exports.create = function (req, res) {
    // replace data assigments with something like
    // {comments: req.body.comments}
    new Auction({
        iso_currency_symbol: 'GBP',
        comments: 'second auction'
    }, function(err, resp) {
console.log('wat');}).save();

    res.send('hello, this is response text');
}


exports.list = function (req, res) {
    Auction.find(function (err, auctions) {
        res.send(auctions);
    });
}

./models/auction.js

var mongoose = require('mongoose'),
    Schema = mongoose.Schema,
    ObjectId = Schema.ObjectId;

var auction_schema = new Schema({
    iso_currency_symbol: String,
    created_date: { type: Date, default: Date.now },
    started_date: { type: Date },
    owner_id: ObjectId,
    comments: String
});

module.exports = mongoose.model('Auction', auction_schema);

[サーバー 2] は私のデータベース サーバーです。その上にmongodbが住んでいます。

[サーバー 1] から、mongo [サーバー 2] を使用して [サーバー 2] に接続できます。つながります。コレクションにレコードを挿入することもできます。

しかし、私のアプリ (上記) では接続しません。[サーバー 2] にはクレイジーなファイアウォールはありません (IP テーブルなどをいじったり、ufw をいじったりしていません)。

Mongoose が接続しない理由を突き止めようとしています。エラーをスローすることさえありません。一体何が起こっているのかわからない (サーバーの問題か、Mongoose 自体の問題か)。

どちらもUbuntuサーバーfwiwです。どんな助けでも素晴らしいでしょう。ありがとう。

4

1 に答える 1

0

database名前が指定されていないようです:

mongoose.connect('mongodb://mongo:mymongopass@[SERVER 2 IP]/databaseName');
mongoose.connect('mongodb://mongo:mymongopass@[SERVER 2 IP]', 'databaseName');

通常、これはデフォルトで になりますtest。ただし、ユーザー/パスはそれを使用するためのアクセス権を持っていない場合があります。

于 2013-09-23T05:48:57.517 に答える