中的1个文档时出现问题谢谢您的关注。mongodb与猫鼬;更新
这里是我的代码:
从型号/ Cart.js
var mongoose = require('mongoose');
var CartSchema = mongoose.Schema({
owner: {type: mongoose.Schema.Types.ObjectId, ref: 'User'},
products: [ {type: mongoose.Schema.Types.ObjectId, ref: 'Product', quantity: Number} ],
created: Date,
updated: Date
});
exports.Cart = mongoose.model('Cart', CartSchema);
从cart.js
var model = require('../models/Cart');
//modify a cart
router.post('/update/:id', function(req, res, next){
var cart = model.Cart();
console.log(cart);
cart.findByIdAndUpdate(req.params.id, {
products: req.body.products,
updated: moment().format()
}, {new:true}, function(err, result){
if(err) throw err;
res.status(200).send(result);
});
});
我得到的错误是undefined is not a function
就在购物车。 findByIdAndUpdate和购物车日志为{ products: [], _id: 56b3b9fcd13a19a87bddd5f3 }
。
你的'/models/Cart.js'是怎么样的?将其代码也包含在问题中! – narainsagar