在app.js上,我有这个:
let Gamestat = require('./models/gamestat');
mongoose.connect(config.database, {
useMongoClient: true
});
let db = mongoose.connection;
io.on('connection', (socket) => {
(...)
socket.on('gameEnded', (data) => {
socket.broadcast.to(data.room).emit('gameEnd', data);
//add game stats to database
let newStat = new Gamestat({
time: 'testing',
winner: 'testing',
loser: 'testing',
moves: 'testing'
});
});
});
/config/database.js:
module.exports = {
database: 'mongodb://localhost/nodekb',
secret: ''
}
我创建gameStatm的app.js的最后一部分已经执行,但是当我在cmd上键入“show collections”时,它不会显示此集合(尽管它显示了其他集合)。我错过了什么?