1
私はMEANアプリケーションで作業していますが、私のDBを更新するX秒ごとにジョブを実行しようとしています。しかし、最初のスプリントとして、エクスプレスサーバー(人口とリスト)の起動時に、いくつかのクエリを起動しようとしています。ここに私のコードは次のとおりです。Mongooseは接続しますが文書を記録しません
// set up ========================
var express = require('express');
var app = express(); // create our app w/ express
var mongoose = require('mongoose'); // mongoose for mongodb
[....]
var Schema = mongoose.Schema;
// configuration =================
// connect to mongoDB database on localhost
var connection = mongoose.createConnection('mongodb://localhost/dv_db_admin');
connection.on('error', console.error.bind(console, 'connection error:'));
connection.once('open', function() {
console.info('connected to database dv_db_admin')
});
[...express stuff...]
// define model =================
var CountrySchema = new Schema({
name : String,
icaoCode : String,
documents : [String]
});
var Country = mongoose.model('Country', CountrySchema);
var country = new Country({
name : 'Afghanistan',
icaoCode : 'AFG',
documents : []
});
country.save(function(err, country) {
if (err) console.log("Error:",err);
console.log("Saved:",country);
});
console.log("After save");
Country.findOne({}, function(err, country) {
if (err) console.log("Error:",err);
console.log("Load:",country);
});
console.log("After find");
app.get('*', function(req, res) {
// load the single view file (angular will handle the page changes on the front-end)
res.sendfile('./public/index.html');
});
// listen (start app with node server.js) ======================================
app.listen(8080);
console.log("App listening on port 8080");
私はそれを起動すると、私は次のログ出力を持っている:
C:\Mercurial\DV-DB-Catalog>npm start
> [email protected] start C:\Mercurial\DV-DB-Catalog
> node server.js
After save
After find
App listening on port 8080
connected to database dv_db_admin
あなたが見ることができるように、保存したり、リストの実行についてのログがありません。私はmongoシェルを実行してshow dbs
を実行しましたが、表示されませんでした。
何が起こっているか知っていますか?
ありがとうございます!
P .:私はバックグラウンドムンゴサービスを実行しています。私は特急サーバーを起動すると、モンゴログには、次のことを示しています
2016-04-15T12:00:50.876+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:50766 #71 (3 connections now open)
2016-04-15T12:00:50.877+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:50767 #72 (4 connections now open)
2016-04-15T12:00:50.878+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:50768 #73 (5 connections now open)
2016-04-15T12:00:50.881+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:50769 #74 (6 connections now open)
こんにちは!まあ... @ Zanonは私に似たような質問に答えました(しかし彼がそれを削除した後)が、どちらもうまくいかなかったように見えます...あなたの答えをありがとう! –