Mongorestore: createIndex error: Values in v:2 index key pattern cannot be of type object. Only numbers > 0, numbers < 0, and strings are allowed

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][1]

source: https://dba.stackexchange.com/questions/250312/failed-to-restored-indexes-using-mongorestore-mongodb