3
我已經定義了這個路由,但是對它的任何請求都被卡在'pending'並且永遠運行。Mongoose .find()方法導致請求掛起
當我登錄的代碼,我看到1
其次是4
,這意味着find方法中的代碼永遠不會被執行
# Calendar routes
router.get '/calendars', (req, res) ->
console.log '1'
Calendar.find (err, calendars) ->
console.log "2" + err
console.log "3" + calendars
res.send(err) if err
res.json(calendars)
return
console.log '4'
return
型號
mongoose = require("mongoose")
module.exports = mongoose.model("Calendar",
name: String
)
爲什麼這是任何想法?
當Mongoose回調未被調用時,通常是因爲該模型的連接未打開。你的'mongoose.connect'調用是否成功? – JohnnyHK 2014-12-06 14:42:58
我該如何檢查? – Tarlen 2014-12-06 15:24:57
爲你的'mongoose.connect'調用提供一個回調函數參數。 – JohnnyHK 2014-12-06 16:00:08