tha*_*ius 1 mongodb mongorestore
我有一个正在尝试恢复的单个集合的现有 mongodump。运行 mongo restore 后,没有错误显示并且数据不在集合中。是否有任何已知的原因会发生这种情况?我希望如果由于某种原因没有插入数据,日志中会提供一个错误。
为了创建并尝试恢复转储,我遵循了为这个问题提供的答案: How to use mongodump for 1 collection
我在另一台服务器上创建了一个新数据库,它有一个空集合。我检查了 mongo 日志文件,没有错误,它显示连接打开并进行身份验证,然后在下一行断开连接。
mongorestore -vvvvv -u user -p 'password' --db=MyDatabase --collection=MyCollection dump1/MyCollection.bson
2015-03-04T18:20:31.331+0000 creating new connection to:127.0.0.1:27017
2015-03-04T18:20:31.332+0000 [ConnectBG] BackgroundJob starting: ConnectBG
2015-03-04T18:20:31.332+0000 connected to server 127.0.0.1:27017 (127.0.0.1)
2015-03-04T18:20:31.332+0000 connected connection!
connected to: 127.0.0.1
2015-03-04T18:20:31.333+0000 drillDown: dump1/MyCollection.bson
2015-03-04T18:20:31.333+0000 dump1/MyCollection.bson
2015-03-04T18:20:31.333+0000 going into namespace [MyDatabase.MyCollection]
Restoring to MyDatabase.MyCollection without dropping. Restored data will be inserted without raising errors; check your server log
file size: 94876
130 objects found
2015-03-04T18:20:31.336+0000 Creating index: { key: { _id: 1 }, name: "_id_", ns: "MyDatabase.MyCollection" }
2015-03-04T18:20:31.340+0000 Creating index: { key: { geometry: "2dsphere" }, name: "geometry_2dsphere", ns: "MyDatabase.MyCollection", 2dsphereIndexVersion: 2 }
Run Code Online (Sandbox Code Playgroud)
日志文件:
2015-03-04T18:20:31.333+0000 [conn874] authenticate db: MyDatabase { authenticate: 1, nonce: "xxx", user: "user", key: "xxx" }
2015-03-04T18:20:31.342+0000 [conn874] end connection 127.0.0.1:59420 (25 connections now open)
Run Code Online (Sandbox Code Playgroud)
我在起点和终点上使用的查询是:
db.MyCollection.find()
Run Code Online (Sandbox Code Playgroud)
在源服务器上,该集合有 130 个元素,这也显示在 mongorestore 输出“130 个对象找到”中。
编辑:
我--drop在 mongorestore 命令中添加了该选项。日志文件输出清楚地表明它正在一个空集合上创建索引。
2015-03-20T15:03:57.565+0000 [conn61965] authenticate db: MyDatabase { authenticate: 1, nonce: "xxx", user: "user", key: "xxx" }
2015-03-20T15:03:57.566+0000 [conn61965] CMD: drop MyDatabase.MyCollection
2015-03-20T15:03:57.631+0000 [conn61965] build index on: MyDatabase.MyCollection properties: { v: 1, key: { _id: 1 }, name: "_id_", ns: "MyDatabase.MyCollection" }
2015-03-20T15:03:57.631+0000 [conn61965] added index to empty collection
2015-03-20T15:03:57.652+0000 [conn61965] build index on: MyDatabase.MyCollection properties: { v: 1, key: { geometry: "2dsphere" }, name: "geometry_2dsphere", ns: "MyDatabase.MyCollection", 2dsphereIndexVersion: 2 }
2015-03-20T15:03:57.652+0000 [conn61965] added index to empty collection
2015-03-20T15:03:57.654+0000 [conn61965] end connection 127.0.0.1:59456 (21 connections now open)
Run Code Online (Sandbox Code Playgroud)
因此,问题最终是我尝试进行还原的用户只有 read 和 dbAdmin 角色。我创建了一个单独的用户,以便应用程序使用的普通用户没有管理权限。将我的用户角色从 read 更改为 readWrite 后,它按预期工作。
老实说,如果用户没有正确的权限,我真的希望日志在尝试在没有正确权限的情况下运行恢复时显示某种错误。
| 归档时间: |
|
| 查看次数: |
5856 次 |
| 最近记录: |