编写了mongo db查询代码,但它没有产生结果。 var cursor = db.collection(' user-data')。find({carManufacturer:{$ eq:toyota}});
你能告诉我如何修复它,提供我的代码
router.get('/cars', function(req, res, next) {
console.log("kumari5");
res.render('cars.hbs');
var toyota = [];
mongo.connect(url, function(err, db) {
assert.equal(null, err);
var cursor = db.collection('user-data').find( { carManufacturer: { $eq: toyota } } );
cursor.forEach(function(doc, err) {
assert.equal(null, err);
toyota.push(doc);
}, function() {
db.close();
res.render('data', {items: toyota});
console.log(toyota);
});
});
});
{
"_id": ObjectId("590a2495bd1d3a356074d36e"),
"DateBough": "21",
"Owner": "Female",
"carManufacturer": ["toyota", "19"],
"Expiry": null
}
{
"_id": ObjectId("347834783478873478788734"),
"DateBough": "21",
"Owner": "Female",
"carManufacturer": ["bmw", "19"],
"Expiry": null
}
{
"_id": ObjectId("34634738468299221182338989"),
"DateBough": "21",
"Owner": "Female",
"carManufacturer": ["benz", "19"],
"Expiry": null
}
{
"_id": ObjectId("47347347834783487437834734"),
"DateBough": "21",
"Owner": "Female",
"carManufacturer": ["toyota", "19"],
"Expiry": null
}