第一种方法:var mongoose = require('mongoose');
var id = mongoose.Types.ObjectId('4edd40c86762e0fb12000003');
第二种方法:
var mongoose = require('mongoose');
var _id = mongoose.mongo.ObjectId("4eb6e7e7e9b7f4194e000001");
正样子就可以
var id = req.query.id;
var sid = mongoose.Types.ObjectId(id);
bookModule.findbook({_id: sid}, function(err, result){
console.log(123123);
console.log(result);
res.render('edit.ejs', {
id: id
});
})
控制台打印的result
结果为
[ { _id: 57fa09d04735eb3f4651fc9b,
name: '123',
author: '123',
readNumber: 123,
__v: 0 } ]
不错不错!!