我需要使用mongodb export命令提取数据
下面是我在mongo db上的数据结构。
{
"_id": "12345",
"name": "Ebo",
"salary": NumberInt(350000),
"age": NumberInt(24)
}
{
"_id": "67891",
"name": "Amir",
"salary": NumberInt(250000),
"age": NumberInt(24)
}我尝试在多个字段中使用export来使用mongoexport,下面是我要生成的命令。
mongoexport --username abc --password abcde --host mymonggodb:27017 --db school
--collection employee --type=csv --authenticationDatabase admin -c records
--query="{'_id': {$in : ['12345','67891','11121314','123456']}}" --fields _id,name,salary,age
--out /Users/axxxx/abcde/monggoextractdata/monggo_employee_data.csv但是我得到了下面这样的错误。
2019-03-07T12:32:23.460+0700 error validating settings:
query '[123 39 95 105 100 39 58 32 123 32 58 32 91 39 51 52 55 52 82 67 39 44 39
51 52 48 54 65 71 39 44 39 51 50 56 50 84 70 39 44 39 51 52 49 48 86 51 39 93
125 125]' is not valid JSON: invalid character ':'
looking for beginning of object key string 2019-03-07T12:32:23.460+0700
try 'mongoexport --help' for more information发布于 2019-12-03 11:20:41
MongoDB documentation中建议的表示法是用单引号将查询括起来,并使用双引号来指定查询中的字段。当使用不同的shell时,单引号和双引号的行为可能不同。在使用mongoexport时,像$in (或$gte,$lte)这样的运算符也应该用双引号括起来。因此,不是:
--query="{'_id': {$in : ['12345','67891','11121314','123456']}}"您应该使用:
--query='{"_id": {"$in" : ["12345","67891","11121314","123456"]}}'最后一条命令是:
mongoexport --username abc --password abcde --host mymonggodb:27017 --db school
--collection employee --type=csv --authenticationDatabase admin -c records
--query='{"_id": {"$in" : ["12345","67891","11121314","123456"]}}'https://stackoverflow.com/questions/55036807
复制相似问题