mongodb 进行 mongoexport 时,“位置选项太多”是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7521163/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 12:15:08  来源:igfitidea点击:

What does "too many positional options" mean when doing a mongoexport?

mongodb

提问by Aarvind

mongoexport -h db.mysite.com -u myUser -p myPass -c myCollection

mongoexport -h db.mysite.com -u myUser -p myPass -c myCollection

But the response I get is:

但我得到的回应是:

ERROR: too many positional options

ERROR: too many positional options

What's that about?

那是关于什么的?

回答by Dean Langford

I had this same problem. In my case, I was using mongoexportwith the --queryoption, which expects a JSON document, such as:

我有同样的问题。就我而言,我使用mongoexport了该--query选项,它需要一个 JSON 文档,例如:

mongoexport ... --query {field: 'value'} ...

I needed to surround the document with quotes:

我需要用引号将文档括起来:

mongoexport ... --query "{field: 'value'}" ...

回答by rowanu

I had the same problem. Found a group post somewhere which said to remove the space between the '-p' and the password, which worked for me.

我有同样的问题。在某处找到了一个小组帖子,上面说要删除“-p”和密码之间的空格,这对我有用。

Your sample command should be:

您的示例命令应该是:

mongoexport -h db.mysite.com -u myUser -pmyPass -c myCollection

回答by HarishThangavel

The same error I have encountered while importing a csv file. But its just, the fact that the field list which you pass for that csv file import may have blank spaces. Just clear the blank spaces in field list.

我在导入 csv 文件时遇到了同样的错误。但它只是,您为该 csv 文件导入传递的字段列表可能有空格。只需清除字段列表中的空格。

Its the parsing error.

它的解析错误。

回答by Sahil Chelaramani

I had the same issue with mongodump. After searching a bit, I found out that using the --outparameter to specify the output directory would solve this issue. The syntax for using the out parameter is

我有同样的问题mongodump。经过一番搜索,我发现使用--out参数指定输出目录可以解决这个问题。使用 out 参数的语法是

mongoexport --collection collection --out collection.json

Also in case your Mongodb instance isn't running, then you could use the --dbpath to specify the exact path to the files of your instance.

此外,如果您的 Mongodb 实例未运行,则您可以使用 --dbpath 指定实例文件的确切路径。

Source: http://docs.mongodb.org/manual/core/import-export/

来源:http: //docs.mongodb.org/manual/core/import-export/

回答by Sean Donders

I had the same issue with the mongoexport utility (using 2.0.2). My fix was to use the FULL parameter name (i.e. not -d, instead use --db).

我在使用 mongoexport 实用程序(使用 2.0.2)时遇到了同样的问题。我的解决方法是使用完整的参数名称(即不是 -d,而是使用 --db)。

回答by Mars Zhu

Sometimes editor will screw it up (such as evernote). I fixed the issue by retyping the command in terminal.

有时编辑器会把它搞砸(比如印象笔记)。我通过在终端中重新输入命令解决了这个问题。

回答by Sudhir Kaushik

I was also stuck in same situation and found what was causing it.

我也陷入了同样的情况,并找到了导致它的原因。

  1. Make sure you are exporting in CSV format by adding parameter --type csv
  2. Make sure there are no spaces in fields name, Example: --fields _id, descis wrong but --fields id,desc,priceis good
  1. 通过添加参数确保以 CSV 格式导出 --type csv
  2. 确保字段名称中没有空格,例如:--fields _id, desc错误但--fields id,desc,price很好

回答by Mulders Michiel

This also works if you place the -c option first. For me, this order does work:

如果您首先放置 -c 选项,这也有效。对我来说,这个顺序确实有效:

mongoexport -c collection -h ds111111.mlab.com:11111 -u user -p pass -d mydb

You can also leave the pass out and the server will ask you to enter the pass. This only works if the server supports SASL authentication (mlab does not for example).

您也可以将通行证留在外面,服务器会要求您输入通行证。这仅在服务器支持 SASL 身份验证(例如 mlab 不支持)时才有效。

回答by Aishwarya Gupta

I had the same issue while using the "mongod --dbpath" command. What I was doing looked somewhat like this:

我在使用“mongod --dbpath”命令时遇到了同样的问题。我正在做的事情看起来有点像这样:

mongod --dbpath c:/Users/HP/Desktop/Mongo_Data

mongod --dbpath c:/Users/HP/Desktop/Mongo_Data

where as the command syntax was supposed to be:

其中命令语法应该是:

mongod --dbpath=c:/Users/HP/Desktop/Mongo_Data

This worked for me. Apart from this one may take a note of the command function and syntaxes using the mongod --helpcommand.

这对我有用。除此之外,可以记下命令功能和使用mongod --help命令的语法。

回答by Hernán Albertario

In my case, I had to write the port separately from the server connection. This worked for me:

就我而言,我必须将端口与服务器连接分开编写。这对我有用:

mongoexport --host=HOST --port=PORT --db=DB --collection=COLLECTION --out=OUTPUT.json -u USER -p PASS

mongoexport --host=HOST --port=PORT --db=DB --collection=COLLECTION --out=OUTPUT.json -u USER -p PASS