小编Oct*_*ius的帖子

我可以动态地将索引添加到Mongoose中的模式吗?

例如,我有以下文档结构:

{
    "subject":"Joe owns a dog", 
    "content":"Dogs are man's best friend", 
    "likes": 60, 
    "year":2015, 
    "language":"english"
}
Run Code Online (Sandbox Code Playgroud)

架构将是:

var schema = new Schema({
    subject: {type: String},
    content: {type: String},
    likes: {type: int},
    year: {type: int},
    language: {type: String}
}

schema.createIndex({"subject": "text"});
Run Code Online (Sandbox Code Playgroud)

我可以动态删除索引并创建另一个包含更多字段的索引吗?

因此,如果现在它在主题字段中搜索关键字,我想动态地更改它并搜索"主题"和"内容".改为:

schema.createIndex({"subject": "text", "content": "text"});
Run Code Online (Sandbox Code Playgroud)

你觉得这可能吗?

非常感谢.

mongoose mongodb node.js mongodb-query

1
推荐指数
1
解决办法
2060
查看次数

标签 统计

mongodb ×1

mongodb-query ×1

mongoose ×1

node.js ×1