I'm trying to dump/restore a mongo collection that has validators. These validators have regexes, which, on the surface, it looks like mongorestore cannot import: First, I create my collection:
use test
db.users.drop()
db.createCollection("users", {validator : {
name : {
$type : "string",
$regex : /^[A-z]*$/
},
}
})
// { "ok" : 1 }
db.getCollectionInfos()
// looks like it should...
db.users.insertOne({"name": "inv@lid"});
// fails
db.users.insertOne({"name": "Valid"});
// succeeds
db.users.find()
// { "_id" : ObjectId("59cd85d84f2803b08e9218ac"), "name" : "Valid" }
Then, I run a dump, which seems fine:
/usr/bin/mongodump --host $MYHOST \
--port $MYPORT \
--db test \
--gzip \
--archive=test.mongodump.gz
Then, a restore, which fails:
/usr/bin/mongorestore --host $MYHOST \
--port $MYPORT \
--gzip \
--archive=test.mongodump.gz
Error:
2017-09-28T23:31:30.626+0000 preparing collections to restore from
2017-09-28T23:31:30.691+0000 reading metadata for test.users from archive 'test.mongodump.gz'
2017-09-28T23:31:30.692+0000 Failed: test.users: error parsing metadata from archive 'test.mongodump.gz': extended json in 'options': expected $regex field to have string value
I've poured over the docs to mongdump and mongorestore, but haven't really gotten anywhere. I have tried --noOptionsRestore
, same error.
I'm relatively new to mongo, so I could just be missing something simple...