Это моя модель.
const mongoose = require('mongoose');
const schema = new mongoose.Schema({
_id: mongoose.Schema.Types.ObjectId,
brandName: {
type: String,
required: true
},
user: {
type: mongoose.Schema.Types.ObjectId,
required: true,
ref: 'User'
},
})
module.exports = mongoose.model('Food', schema);
Я хочу сохранить идентификатор пользователя как ссылку на коллекцию продуктов питания.
const newFood = new Food({
_id: new mongoose.Types.ObjectId,
brandName: req.body.brandName,
user = mongoose.Types.ObjectId(req.body.userId),
})
Теперь я получаю эту ошибку консоли.
user = mongoose.Types.ObjectId(req.body.userId),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Invalid shorthand property initializer
Я не уверен, что я делаю неправильно.