将输出重定向到MongoDB中的文本文件 [英] Redirecting the output to a text file in MongoDB

查看:263
本文介绍了将输出重定向到MongoDB中的文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将mongodb命令的输出重定向到文件中,但是不起作用.我在网上搜索了很多内容,但是没有一个命令对我有用.

I want to redirect the output of a mongodb command into a file, but it's not working. I searched a lot on the net, but none of the commands worked for me.

> mongo --quiet 99.99.99.99/db --eval 'printjson(db.productAttribute.distinct('productId'))' > /home/myname/output_query.json

Wed May 13 12:28:58.022 SyntaxError: Unexpected identifier

> mongo --quiet db --eval 'printjson(db.productAttribute.distinct('productId'))' > /home/myname/output_query.json

Wed May 13 12:29:09.896 SyntaxError: Unexpected identifier

该命令很简单,我不想将其放入单独的.js文件中.另外,我正在尝试从mongodb shell本身执行此命令.

The command is simple, and I don't want to put it into a separate .js file. Also, I am trying to execute this command from the mongodb shell itself.

推荐答案

首先,您不应该在mongo shell中运行它.这只能在linux shell中使用,因为linux shell中提供了mongo可执行文件,但是您正尝试从mongo shell中调用mongo可执行文件.

First, you should not run this in mongo shell. This will only work from linux shell as mongo executable is available in linux shell, but you are trying to call mongo executable from inside mongo shell.

第二,在命令中使用双引号.

Second, use double quotes in your command.

因此,打开一个终端窗口并运行以下命令.会起作用的.

So, open a terminal window and run the following. It will work.

$ mongo --quiet 99.99.99.99/db --eval 'printjson(db.productAttribute.distinct("productId"))' > /home/myname/output_query.json

这篇关于将输出重定向到MongoDB中的文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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