patternMinor
Mongoose: Change 2dsphere index version
Viewed 0 times
indexmongooseversion2dspherechange
Problem
I'm trying to upload my database to the heroku mongodbLab addon. My MongoDB version is 3.2.4 and my servers is 3.0.9. Mongoose is 4.4.6. However, when I run the command
How can I change the 2dsphereIndexVersion in my schema?
Here's my schema file for my db:
As you can see I tried to change it by adding that attribute
-EDIT-
I'm using mongoose to create the database with the schema above. I am trying to set t
$ mongorestore -h myhostname -d mydatabase -u username -p password ~/tmp/mongodump/Loc8r to push the db to heroku I get the error: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]How can I change the 2dsphereIndexVersion in my schema?
Here's my schema file for my db:
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);
As you can see I tried to change it by adding that attribute
"2dsphereIndexVersion": 2. However, that didn't work. Anyone know how I can change this?-EDIT-
I'm using mongoose to create the database with the schema above. I am trying to set t
Solution
I ended up changing the .metadata.json file to look like this:
{"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}]}Code Snippets
{"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}]}Context
StackExchange Database Administrators Q#131936, answer score: 3
Revisions (0)
No revisions yet.