json mongodb-error 验证设置:只允许一个位置参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30953611/
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-03 17:56:52  来源:igfitidea点击:

mongodb-error validating settings: only one positional argument is allowed

jsonmongodbmongoimport

提问by Roudy Tarabay

I just moved to a new laptop which had mongo 3.0.0 I believe. On the new laptop I have mongo 3.0.4. and trying the script that was working on the old laptop is giving me errors. This line is giving me the error.

我刚搬到一台新的笔记本电脑,我相信它有 mongo 3.0.0。在新的笔记本电脑上,我有 mongo 3.0.4。并尝试在旧笔记本电脑上运行的脚本给了我错误。这条线给了我错误。

mongoimport --host localhost \
            -db roudy123_q \
            -collection LebaneseAmericanUniversity\(Lebanon\).json \
            --file LebaneseAmericanUniversity\(Lebanon\).json \
            --jsonArray

error validating settings: only one positional argument is allowed.

错误验证设置:只允许一个位置参数。

I googled the error and the only relevant result was the source code of mongoimport. So I guess it has something to do with the new version.

我用谷歌搜索了错误,唯一相关的结果是 mongoimport 的源代码。所以我想这与新版本有关。

回答by Sylvain Leroux

Just a wild guess...

只是一个疯狂的猜测......

... but the various long options should be specified using --, not -:

...但应使用指定的各种长选项--,而不是-

mongoimport --host localhost \
            --db roudy123_q \
            --collection LebaneseAmericanUniversity\(Lebanon\).json \
            --file LebaneseAmericanUniversity\(Lebanon\).json \
            --jsonArray

Maybe this particular version of mongoimportis more punctilious about that, and will treat -db ... -collection ...as positional arguments rather than keyword arguments ?

也许这个特定版本的mongoimport对此更加谨慎,并将-db ... -collection ...视为位置参数而不是关键字参数?

回答by rakshith91

This error can also occur if white spaces are given without a "\" in the path to the file . Ex: This wont work: Error

如果在文件路径中给出的空格没有“\”,也会发生此错误。例如:这行不通: 错误

But this would work :

但这会起作用:

works fine

工作正常

回答by kapil pandey

None of the above mentioned answers solved my problem but they indeed helped me in figuring out what I was doing wrong.

以上提到的答案都没有解决我的问题,但它们确实帮助我弄清楚我做错了什么。

1)using -d instead of --d (shorthand only require one - not two --)

1) 使用 -d 而不是 --d (速记只需要一个 - 而不是两个 --)

2)using "" for absolute file path.

2)使用“”作为绝对文件路径。

For example my files location in windows is: C:\kp github\other projects\projectXyz\myFile.csv

例如我在 windows 中的文件位置是:C:\kp github\other projects\projectXyz\myFile.csv

So for me the command that worked was: mongoimport -d users -c contacts --type=csv --headerline --file="C:\kp github\other projects\projectXyz\myFile.csv"

所以对我来说,有效的命令是: mongoimport -d users -c contacts --type=csv --headerline --file="C:\kp github\other projects\projectXyz\myFile.csv"

where users is my db name and contacts is my collection name

其中用户是我的数据库名称,联系人是我的收藏名称

回答by Ankit Marothi

If you get this error while inserting fields with --fields, the probable reason might be you are using spaces to do that.

如果您在使用 --fields 插入字段时遇到此错误,可能的原因可能是您使用空格来执行此操作。

Both -f and --fields should work in those cases Using Mongo Version 3.0.6

-f 和 --fields 都应该在这些情况下工作使用 Mongo 版本 3.0.6

mongoimport --db logs --collection action_logs --type tsv -f updated_at ,transaction_time ,origin  --file parsed.tsv
mongoimport --db logs --collection action_logs --type tsv -f updated_at,transaction_time,origin  --file parsed.tsv

回答by Mohan

I think giving a white spaces in the file name of directory will also contribute to this error.

我认为在目录的文件名中添加空格也会导致此错误。