我一直在节点和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