MongoDB从3.2转储,恢复为3.4,错误索引safe = null

Pat*_*zlo 28 mongodb mongorestore mongodump

我收到以下错误(转储MongoDB 3.2)(恢复MongoDB 3.4):

Failed: ngivr-dev.ledgerhelpers: error creating indexes for ngivr-dev.ledgerhelpers: **createIndex error:** **The field 'safe' is not valid for an index specification.** Specification: **{ unique: true, name: "ledgerId_1", safe: null, ns: "ngivr-dev.ledgerhelpers", background: true, key: { ledgerId: 1 } }**
Run Code Online (Sandbox Code Playgroud)

看起来安全索引为null.但是我如何在MongoDB 3.4中使用它?3.2没关系.

ser*_*iuz 57

safe=true 不是索引规范.

在早期版本的MongoDB中,低于3.4,可以添加额外的索引规范.那些被特定的司机使用.

在3.4中,mongodb添加了对索引规范的验证:

确保指定的索引选项有效.以前的版本忽略无效选项.

这就是你有这个错误的原因.我担心您需要确保3.2版本中的索引没有无效的索引规范,然后执行mongodump.

正如kz_sergey在他的回答中所说,你可以mongorestore使用--noIndexRestore,这应该可以正常工作.

  • 应该在`mongorestore`命令中使用`--noIndexRestore`选项,而不是`mongodump`命令. (12认同)
  • 你完全正确:我正在使用 mLab 来托管我的 mongodb,需要时更新版本(从 2.x 到 3.2),我忽略了我的一些旧索引(在 2.x 中创建)包含属性`safe : 空`。对我来说,正是这个旧规范造成了导入问题。重新创建这些索引没有解决问题。坦克! (2认同)

kz_*_*gey 21

为什么要恢复索引?--noIndexRestore并再次创建它们.