Mongodb在每个对象中插入ID

时间:2019-07-18 01:58:36

标签: javascript node.js mongodb mongoose

我是Mongo的新手,请问这是一个愚蠢的问题。

我知道Mongo在父级对象上插入_id作为主键,但是为每个字段插入_id是正常的,还是我犯了某种错误。

还有__v字段是什么?

enter image description here

这是我形成此对象的方式:

模式/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字段来自哪里?

0 个答案:

没有答案