gpt4 book ai didi

mongodb - Mongoose 中的嵌套对象模式

转载 作者:可可西里 更新时间:2023-11-01 09:13:17 27 4
gpt4 key购买 nike

假设我有这样的模式

var Language = new Schema({
name: { type: String, unique: true, required: true },
pos: [{
name: String,
attributes: [{
name: String
}]
}]
});

posattributes 中的每个项目是否都有一个 _id?如果我将唯一索引添加到 pos 数组中的 name 字段,唯一性是只对那个数组强制执行,还是对所有条目都是唯一的?

最佳答案

不,没有自己架构的嵌入文档,如 posattributes 没有 _id 属性。

如果将唯一索引添加到 pos 数组中的 name 字段,将在整个集合中强制执行唯一性,但不会在集合中单个文档的数组。参见 this post .

关于mongodb - Mongoose 中的嵌套对象模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11917808/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com