无法使用 mongorestore 恢复索引 - MongoDB

Abd*_*oiz 5 mongodb mongorestore

注意:我已经知道 --noIndexRestore

我有一个具有以下文档结构的组织集合,

{
    "_id" : ObjectId("5cc2bf9f5ca45131b8f8e427"),
    "name" : "National",
    "parent" : "null",
    "level" : 1,
    "label" : "National",
    "identifier" : "Default",
    "client_id" : ObjectId("5af3178c141292374cbf363e")
}
Run Code Online (Sandbox Code Playgroud)

我已经在以下字段上创建了索引,

  1. 姓名
  2. 家长
  3. 等级
  4. 标识符
  5. 客户ID

当我检查索引时,

db.org.getIndexes();
Run Code Online (Sandbox Code Playgroud)

结果:

/* 1 */
{
    "v" : 2,
    "key" : {
        "_id" : 1
    },
    "name" : "_id_",
    "ns" : "testdbname.org"
},

/* 2 */
{
    "v" : 2,
    "key" : {
        "name" : 1
    },
    "name" : "name_1",
    "ns" : "testdbname.org"
},

/* 3 */
{
    "v" : 2,
    "key" : {
        "parent" : 1
    },
    "name" : "parent_1",
    "ns" : "testdbname.org"
},

/* 4 */
{
    "v" : 2,
    "key" : {
        "level" : 1
    },
    "name" : "level_1",
    "ns" : "testdbname.org"
},

/* 5 */
{
    "v" : 2,
    "key" : {
        "identifier" : 1
    },
    "name" : "identifier_1",
    "ns" : "testdbname.org"
},

/* 6 */
{
    "v" : 2,
    "key" : {
        "client_id" : 1
    },
    "name" : "client_id_1",
    "ns" : "testdbname.org"
}
Run Code Online (Sandbox Code Playgroud)

上述所有指标对我来说看起来都很好。但是,当我在服务器上进行备份并将其恢复到其他地方时,在恢复组织集合时会出现以下错误。

reading metadata for testdbname.org from archive 'testdbname_05-10-2019_00%3A55%3A31.archive'
2019-10-05T10:20:40.979+0500    restoring testdbname.org from archive 'testdbname_05-10-2019_00%3A55%3A31.archive'
2019-10-05T10:20:41.226+0500    reading metadata for testdbname.questionbank from archive 'testdbname_05-10-2019_00%3A55%3A31.archive'
2019-10-05T10:20:41.237+0500    restoring indexes for collection testdbname.org from metadata
2019-10-05T10:20:41.240+0500    Failed: testdbname.org: error creating indexes for testdbname.org: createIndex error: Values in v:2 index key pattern cannot be of type object. Only numbers > 0, numbers < 0, and strings are allowed.
Run Code Online (Sandbox Code Playgroud)

Abd*_*oiz 4

对于将来来到这里的人来说,问题是,我在本地使用 MongoDB 4.0,而服务器使用 4.2:

从版本 4.2 开始,mongodump 对元数据文件使用扩展 JSON v2.0(规范)格式。要解析这些文件以进行恢复,请使用支持扩展 JSON v2.0(规范或宽松模式)格式的 mongorestore 版本 4.2+。有关详细信息,请参阅“元数据格式”部分:docs.mongodb.com/manual/reference/program/mongodump