【发布时间】:2019-03-10 22:12:59
【问题描述】:
我有一个 Mongoose 架构,其中包含一个具有特定索引的字段:
const reportSchema = new mongoose.Schema({
coords: {
type: [Number],
required: true,
index: '2dsphere'
},
…
}
它在我的本地机器上运行良好,所以当我通过 shell 连接到 MongoDB 时,我会得到 db.reports.getIndexes() 的输出:
[
{
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "weatherApp.reports"
},
{
"v" : 2,
"key" : {
"coords" : "2dsphere"
},
"name" : "coords_2dsphere",
"ns" : "weatherApp.reports",
"background" : true,
"2dsphereIndexVersion" : 3
}
]
然后我将此应用程序部署到 Heroku 并连接到 MongoDB Atlas 而不是我的本地数据库。它适用于保存和检索数据,但没有创建索引(仅默认一个):
[
{
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "weatherApp.reports"
}
]
什么可能导致这个问题? Atlas 允许通过 Web GUI 创建索引,它可以很好地工作以及从 shell 中创建索引。但由于某种原因,Mongoose 无法执行此操作。
【问题讨论】:
-
您可以查看地图集日志吗?此外,您自动迁移您的数据?插入数据后索引仍然不存在?
-
@anouarKacem,不,插入数据后仍然没有索引。试图检查 Atlas 上的日志,但实际上无法弄清楚在哪里可以访问它们。
-
@MishaGoncharov 你有没有发现问题是什么?
-
@Joseph,不幸的是,没有。阿特拉斯支持也没有帮助:-(
-
@MishaGoncharov 我刚刚弄清楚我出了什么问题。我会提交一个答案。
标签: mongodb mongoose mongodb-atlas