在我的主文件server.js我有以下功能:Node.js |類型錯誤:[...]是不是一個函數
server.js
const mongoose = require('mongoose');
const SmallRounds = require('./models/smallrounds.js');
function initRound(){
logger.info('Initializing round...');
SmallRounds.getLatestRound((err, data) => {
[...]
});
}
功能getLatestRound()在得到我的出口貓鼬模型smallrounds.js
smallrounds.js
const mongoose = require('mongoose');
const config = require('../config.js');
const SmallRoundsSchema = mongoose.Schema({
[...]
});
const SmallRounds = module.exports = mongoose.model('SmallRounds', SmallRoundsSchema);
module.exports.getLatestRound = function(callback){
SmallRounds.findOne().sort({ created_at: -1 }).exec((err, data) => {
if(err) {
callback(new Error('Error querying SmallRounds'));
return;
}
callback(null, data)
});
}
但是當我打電話initRound()我得到以下錯誤:
TypeError: SmallRounds.getLatestRound is not a function
at initRound (E:\Projects\CSGOOrb\server.js:393:14)
at Server.server.listen (E:\Projects\CSGOOrb\server.js:372:2)
at Object.onceWrapper (events.js:314:30)
at emitNone (events.js:110:20)
at Server.emit (events.js:207:7)
at emitListeningNT (net.js:1346:10)
at _combinedTickCallback (internal/process/next_tick.js:135:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
at Function.Module.runMain (module.js:607:11)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:575:3
這究竟是爲什麼?我不認爲我有循環依賴關係,沒有任何拼寫錯誤。謝謝:)
也許'mongoose.model'中返回的對象被凍結或者什麼?確保您要求的文件與本文中的完全相同。 – MinusFour
這是,我複製粘貼代碼 –