从MongoDB导出system.profile不起作用

时间:2013-07-26 12:19:34

标签: mongodb

我正在尝试导出:

ilya@server ~]$ mongoexport --host localhost --port 27000  --collection system.users --db mydb --out profile.json                
connected to: localhost:27000
exported 1 records

system.users

一起使用

但不适用于system.profile

[ilya@server ~]$ mongoexport --host localhost --port 27000  --collection system.profile --db mydb --out profile.json
connected to: localhost:27000
exported 0 records

收藏不是空的:

[ilya@server ~]$ mongo localhost:27000/mydb
MongoDB shell version: 2.2.3
connecting to: localhost:27000/mydb
mongos> db.system.profile.count();
1044

我需要将这些行导出并在某处使用它们,例如与普通集合一样(不限制为system.profile)。

1 个答案:

答案 0 :(得分:3)

来自database-profiling-and-sharding

  

您无法在mongos实例上启用分析。启用分析   在分片群集中,您必须为每个mongod实例启用分析   在群集中。

另见mongoexport only exports one shard's worth of data(尽管自1.9.1以来这个错误已修复,你使用的版本更晚了)

请尝试直接从包含所需mongoexport集合的 mongod 实例system.profile开始。

<强> **UPDATE**

第二种方法是不使用mongoexport,而是直接从mongo shell获取集合(因为你可以从mongo shell中看到集合)。

要做到这一点,首先编写以下脚本并将其保存到print-profile.js

c = db.system.profile.find();
while(c.hasNext()) {
  printjson(c.next());
}

然后从bash shell执行以下行:

mongo localhost:27000/mydb print-profile.js  > profile.json

等一下,在profile.json中,您将获得所需的数据。