var express = require('express');
var router = express.Router();
var Product = require('../models/products');
/* GET home page. */
router.get('/', function(req, res, next) {
var products = Product.find();
res.render('shops/index', { title: 'Express' ,Product:products});
});
module.exports = router;
我是nodejs和mongodb的新手。我在数据库中有5条记录,但是上面的代码从数据库中返回了15条记录
这是实现的模型
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var schema = new Schema({
imagePath:{type: String,required:true},
title:{type: String,required:true},
description:{type: String,required:true},
price:{type: String,required:true},
});
module.exports = mongoose.model('Product',schema);
答案 0 :(得分:0)
find是一个异步操作,其结果在回调函数中提供。查询如下:
Product.find({}, function(err, products) () {
res.json(products);
});
但是我不明白为什么你得到15个结果...