【发布时间】:2017-10-10 06:54:13
【问题描述】:
我正在尝试转储/恢复具有验证器的 mongo 集合。这些验证器有正则表达式,从表面上看,mongorestore 似乎无法导入: 首先,我创建我的收藏:
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" }
然后,我运行一个转储,这似乎很好:
/usr/bin/mongodump --host $MYHOST \
--port $MYPORT \
--db test \
--gzip \
--archive=test.mongodump.gz
然后,还原失败:
/usr/bin/mongorestore --host $MYHOST \
--port $MYPORT \
--gzip \
--archive=test.mongodump.gz
错误:
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
我已将文档倾注到 mongorestore 和 mongorestore,但还没有真正得到任何结果。我试过--noOptionsRestore,同样的错误。
我对 mongo 比较陌生,所以我可能会遗漏一些简单的东西......
【问题讨论】:
标签: mongodb mongodump mongorestore