首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >猫鼬:更改2dsphere索引版本

猫鼬:更改2dsphere索引版本
EN

Database Administration用户
提问于 2016-03-10 22:33:19
回答 1查看 1.2K关注 0票数 3

我正试图将我的数据库上传到heroku mongodbLab插件。我的MongoDB版本为3.2.4,服务器为3.0.9。猫鼬是4.4.6。然而,当我运行命令$ mongorestore -h myhostname -d mydatabase -u username -p password ~/tmp/mongodump/Loc8r将db推到heroku时,我得到了错误:

代码语言:javascript
复制
building a list of collections to restore from /Users/user/tmp/mongodump/Loc8r dir
reading metadata for database.locations from /Users/user/tmp/mongodump/Loc8r/locations.metadata.json
restoring database.locations from /Users/user/tmp/mongodump/Loc8r/locations.bson
restoring indexes for collection database.locations from metadata
Failed: database.locations: error creating indexes for database.locations: createIndex error: exception: unsupported geo index version { 2dsphereIndexVersion : 2dsphereIndexVersion: 3 }, only support versions: [1,2]

如何在我的模式中更改2dsphereIndexVersion?

下面是我的db的模式文件:

代码语言:javascript
复制
var mongoose = require('mongoose');

var openingTimesSchema = new mongoose.Schema({
  days: {type: String, required: true},
  opening: String,
  closing: String,
  closed: {type: Boolean, required: true}
});

var reviewSchema = new mongoose.Schema({
  author: String,
  rating: {type: Number, required: true, min: 0, max: 5},
  reviewText: String,
  createdOn: {type: Date, "default": Date.now}
});

var locationSchema = new mongoose.Schema({
  name: {type:String, required: true},
  address: String,
  rating: {type: Number, "default": 0, min: 0, max: 5},
  facilities: [String],
  coords: {type: [Number], index: '2dsphere', "2dsphereIndexVersion": 2},
  openingTimes: [openingTimesSchema],
  reviews: [reviewSchema]
});

mongoose.model('Location', locationSchema);

如您所见,我试图通过添加属性"2dsphereIndexVersion": 2来更改它。然而,这是行不通的。有人知道我怎么能改变这个吗?

-编辑-我正在用上面的模式创建数据库。我试图将"2dsphereIndexVersion"设置为2,因为MongoDB的服务器版本需要它。

EN

回答 1

Database Administration用户

发布于 2016-03-11 00:17:51

最后我将.metadata.json文件更改为如下所示:

代码语言:javascript
复制
{"options":{},"indexes":[{"v":1,"key":{"_id":1},"name":"_id_","ns":"Loc8r.locations"},{"v":1,"key":{"coords":"2dsphere"},"name":"coords_2dsphere","ns":"Loc8r.locations","background":true,"2dsphereIndexVersion":2}]}
票数 3
EN
页面原文内容由Database Administration提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://dba.stackexchange.com/questions/131936

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档