我一直在節點和mongo一段時間,但現在這個問題沒有得到解決現在問題: 這是我的代碼:顯示爲_id鑄造錯誤,但ID從未使用節點js
router.get('/getLocBJ', function(req, res) {
mongoose.model('Locations').find({
}, function(err, locations) {
res.format({
json: function() {
res.json(locations);
}
});
}).limit(500);
});
每當我把這個API 我所期望的:它顯示我此錯誤:應該從收集 發生了什麼事返回500行
GET Error: There was a problem retrieving: CastError: Cast to ObjectId failed for value "getLocBJ" at path "_id"
我所做之前:我試圖返回一些特定的值如「_id,lat & lng」從那以後,它顯示了同樣的錯誤,即使從函數中刪除罪魁禍首代碼似乎沒有工作。 嘗試清除系統緩存但沒有成功。
編輯使用的模式:
var mongoose = require('mongoose');
var locationSchema = new mongoose.Schema({
trackernumber: String,
cdate : String,
accountId : String,
time : String,
speed : String,
lat : String,
lng : String,
orientation:String,
createdDate:Date,
rowData:{},
alarm_code : String,
distance : String,
alarm : {},
locFlag : String
});
mongoose.model('Locations', locationSchema);
的_id字段自動生成的我還沒有手動和爲你建議我嘗試使用,但仍是同樣的結果代碼添加它。 – VishAl
你能顯示你的模式嗎? –
好吧,請檢查編輯 – VishAl