最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

如何在猫鼬中设置外键。?

运维笔记admin7浏览0评论

如何在猫鼬中设置外键。?

如何在猫鼬中设置外键。?

我需要将另一个集合中的字段设置为我的猫鼬模式的外键。

我对“ productSchema”有一个计数器“ pid”。我需要将“ pid”设置为“ orderSchema”的外键。

    const orderSchema = mongoose.Schema({
    id: mongoose.Schema.Types.ObjectId,
    product: { type: mongoose.Schema.Types.ObjectId, ref: 'Product', 
    required: 
    true },
    quantity: { type: Number, default: 1 }
    });

    const productSchema = mongoose.Schema({
    _id: mongoose.Schema.Types.ObjectId,
    name: { type: String, required: true },
    price: { type: Number, required: true },
    productImage: { type: String }
    });

我需要将另一个集合中的字段设置为我的猫鼬模式的外键。我对“ productSchema”有一个计数器“ pid”。我需要将“ pid”设置为“ orderSchema” const的外键...

回答如下:

Well MongoDB不是关系数据库,因此它不支持外键之类的概念。在mongoDB中,您必须以一种可以轻松获取信息的方式来构造数据。

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论