从 MongoDB 导出 system.profile 不起作用 [英] Exporting system.profile from MongoDB doesn't work

查看:57
本文介绍了从 MongoDB 导出 system.profile 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试导出:

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

I need these rows to export and work with them somewhere, for example as with normal collection(not capped as system.profile).

推荐答案

来自 数据库分析和分片:

您不能在 mongos 实例上启用分析.启用分析在分片集群中,您必须为每个 mongod 实例启用分析在集群中.

You cannot enable profiling on a mongos instance. To enable profiling in a shard cluster, you must enable profiling for each mongod instance in the cluster.

另见mongoexport 只导出一个分片的数据(虽然这个bug已修复从 1.9.1 开始,您使用的是更高版本)

Also see mongoexport only exports one shard's worth of data (although this bug is fixed since 1.9.1 and you use a much later version)

所以尝试直接从 mongod 实例中 mongoexport 保存你想要的 system.profile 集合.

So try to mongoexport directly from the mongod instance that holds the system.profile collection you want.

**UPDATE**

第二种方法是不使用 mongoexport,而是直接从 mongo shell 获取集合(因为您可以从 mongo shell 内部看到该集合).

A second approach is to not use mongoexport but to take the collection directly from the mongo shell (since you are able to see the collection from inside the mongo shell).

首先编写以下脚本并将其保存到 print-profile.js

To do that first write the following script and save it to print-profile.js

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

然后从 bash shell 执行以下行:

then execute the following line from the bash shell:

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

稍等片刻,在 profile.json 中,您将获得所需的数据.

Wait a little and in profile.json you will have the data you need.

这篇关于从 MongoDB 导出 system.profile 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆