2

Note: I already know about --noIndexRestore

I have an org collection with the following document structure,

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

I have created the indexes on the following fields,

  1. name
  2. parent
  3. level
  4. identifier
  5. client_id

When I check indexes,

db.org.getIndexes();

Result:

/* 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"
}

All of the above indexes looks fine to me. But when I take backup on server and restore it somewhere else it gives me the following error while restoring the org collection.

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.
2

For the people who will come here in the future the issue was, I was using MongoDB 4.0 on the local and server was on 4.2:

Starting in version 4.2, mongodump uses Extended JSON v2.0 (Canonical) format for the metadata files. To parse these files for restore, use mongorestore version 4.2+ that supports Extended JSON v2.0 (Canonical or Relaxed mode) format. For details please see "Metadata Format" section on this : docs.mongodb.com/manual/reference/program/mongodump

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.