我是Mongo的新手,请问这是一个愚蠢的问题。
我知道Mongo在父级对象上插入_id作为主键,但是为每个字段插入_id是正常的,还是我犯了某种错误。
还有__v字段是什么?
这是我形成此对象的方式:
模式/models/Restaurant.js
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const Restaurants = new Schema({
name: String,
categories: [{
sandwiches: [{
name: String,
description: String,
img: String,
price: String
}]
}]
})
module.exports = mongoose.model('Restaurants', Restaurants);
我要播种的地方:
seed.js
const rest = new Restaurants({
name: "taco bell",
categories: [{
sandwiches: [{
name: "breadedChickenFlatbread",
description: "A good sandwich",
img: "./sandwich.jpg",
price: "$8.99"
}]
}]
});
rest.save(() => {})
我看到的所有_id字段正常吗?另外,__v字段来自哪里?