[英]How do I query the database using Mongodb after I set up a Mongoose schema for authentication?
[英]Mongoose schema update is not pick it up by Mongodb database
我已经创建了具有以下架构的数据库:
const ProjectSchema = new mongoose.Schema({
name: { type: String },
description: { type: String },
client: {
type: mongoose.Schema.Types.ObjectId,
ref: 'client'
},
group: {
type: mongoose.Schema.Types.ObjectId,
ref: 'project_group'
}
});
我需要将架构更改为
const ProjectSchema = new mongoose.Schema({
name: { type: String, unique: true, required: true },
description: { type: String },
client: {
type: mongoose.Schema.Types.ObjectId,
ref: 'client'
},
group: {
type: mongoose.Schema.Types.ObjectId,
ref: 'project_group'
}
});
因为我们需要强制名称唯一且不能为null。 更改此定义后,我看到db仍保存具有相同名称值的文档。 我的问题是,如何应用在架构中所做的任何更改? 而且,如何自动执行此操作而无需手动执行此操作?
问候
您很可能需要对该字段建立索引,以便可以快速对其进行搜索。 如果还没有,请重新启动服务器。 如果您拥有MongoDB指南针(官方的MongoDB GUI),这很容易做到,或者您可以阅读此文档。 https://docs.mongodb.com/manual/core/index-single/#create-an-index-on-an-embedded-field
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.