mongoexport JSON断言:10340解析JSON字符串失败

时间:2022-05-29 23:17:20

I'm trying to export CSV file list from mongoDB and save the output file to my directory, which is /home/asaj/. The output file should have the following columns: name, file_name, d_start and d_end. The query should filter data with status equal to "FU" or "FD", and d_end > Dec. 10, 2012.

我正在尝试从mongoDB导出CSV文件列表并将输出文件保存到我的目录,即/ home / asaj /。输出文件应包含以下列:name,file_name,d_start和d_end。查询应过滤状态等于“FU”或“FD”和d_end> 2012年12月10日的数据。

In mongoDB, the query is working properly. The query below is limited to 1 data output. See query below:

在mongoDB中,查询正常工作。以下查询仅限于1个数据输出。请参阅以下查询:

> db.Samples.find({ $or : [ { status : 'FU' }, { status : 'FD'} ], d_end : { $gte : ISODate("2012-12-10T00:00:00.000Z") } }, {_id: 0, name: 1, file_name: 1, d_start: 1, d_end: 1}).limit(1).toArray();
[
    {
            "name" : "sample"
            "file_name" : "sample.jpg",
            "d_end" : ISODate("2012-12-10T05:1:57.879Z"),
            "d_start" : ISODate("2012-12-10T02:31:34.560Z"),
    }

]
>

In CLI, mongoexport command looks like this:

在CLI中,mongoexport命令如下所示:

mongoexport -d maindb -c Samples -f "name, file_name, d_start, d_end" -q "{'\$or' : [ { 'status' : 'FU' }, { 'status' : 'FD'} ] , 'd_end' : { '\$gte' : ISODate("2012-12-10T00:00:00.000Z") } }" --csv -o "/home/asaj/currentlist.csv"

But i always ended up with this error:

但我总是得到这个错误:

connected to: 127.0.0.1
Wed Dec 19 16:58:17 Assertion: 10340:Failure parsing JSON string near: , 'd_end
0x5858b2 0x528cb4 0x52902e 0xa9a631 0xa93e4d 0xa97de2 0x31b441ecdd 0x4fd289
mongoexport(_ZN5mongo11msgassertedEiPKc+0x112) [0x5858b2]
mongoexport(_ZN5mongo8fromjsonEPKcPi+0x444) [0x528cb4]
mongoexport(_ZN5mongo8fromjsonERKSs+0xe) [0x52902e]
mongoexport(_ZN6Export3runEv+0x7b1) [0xa9a631]
mongoexport(_ZN5mongo4Tool4mainEiPPc+0x169d) [0xa93e4d]
mongoexport(main+0x32) [0xa97de2]
/lib64/libc.so.6(__libc_start_main+0xfd) [0x31b441ecdd]
mongoexport(__gxx_personality_v0+0x3c9) [0x4fd289]
assertion: 10340 Failure parsing JSON string near: , 'd_end

I'm having error in ", 'd_end' " in mongoexport CLI. I'm not so sure if it is a JSON syntax error because query works on MongoDB. Please help.

我在mongoexport CLI中的“,'d_end'”中出错了。我不太确定它是否是JSON语法错误,因为查询适用于MongoDB。请帮忙。

2 个解决方案

#1


2  

After asking someone knows MongoDB better than me, we found out that the problem is the

在询问有人比我更了解MongoDB之后,我们发现问题就在于此

ISODate("2012-12-10T00:00:00.000Z")

We found the answer on this question: mongoexport JSON parsing error

我们在这个问题上找到了答案:mongoexport JSON解析错误

To resolve this error, first, we convert it to strtotime:

要解决此错误,首先,我们将其转换为strtotime:

php > echo strtotime("12/10/2012");
1355126400

Next, multiple strtotime result by 1000. This date will looks like this:

接下来,多个strtotime结果为1000.此日期将如下所示:

1355126400000

Lastly, change ISODate("2012-12-10T00:00:00.000Z") to new Date(1355126400000) in the mongoexport command.

最后,在mongoexport命令中将ISODate(“2012-12-10T00:00:00.000Z”)更改为新日期(1355126400000)。

Now, the CLI mongoexport looks like this and it works:

现在,CLI mongoexport看起来像这样,它可以工作:

mongoexport -d maindb -c Samples -f "id,file_name,d_start,d_end" -q "{'\$or' : [ { 'status' : 'FU' }, { 'status' : 'FD'} ] , 'd_end' : { '\$gte' : new  Date(1355126400000) } }" --csv -o "/home/asaj/listupdate.csv"

Note: remove space between each field names in -f or --fields option.

注意:在-f或--fields选项中删除每个字段名称之间的空格。

#2


2  

I know it has little to do with this question, but the title of this post brought it up in Google so since I was getting the exact same error I'll add an answer. Hopefully it helps someone.

我知道这与这个问题没什么关系,但是这篇文章的标题在Google上提出来,所以因为我得到完全相同的错误,我会添加一个答案。希望它可以帮助某人。

My issue was adding a MongoId query for _id to a mongoexport console command on Windows. Here's the error:

我的问题是在Windows上将_id的MongoId查询添加到mongoexport控制台命令。这是错误:

Assertion: 10340:Failure parsing JSON string near: _id

The problem ended up being that I needed to wrap the JSON query in double quotes, and the ObjectId had to be in double quotes (not single!), so I had to escape those quotes. Here's the final query that worked, for future reference:

问题最终是我需要用双引号包装JSON查询,并且ObjectId必须是双引号(不是单引号!),所以我不得不逃避这些引号。这是最终的查询,以供将来参考:

 mongoexport -u USERNAME -pPASSWORD -d DATABASE -c COLLECTION 
   --query "{_id : ObjectId(\"5148894d98981be01e000011\")}"

#1


2  

After asking someone knows MongoDB better than me, we found out that the problem is the

在询问有人比我更了解MongoDB之后,我们发现问题就在于此

ISODate("2012-12-10T00:00:00.000Z")

We found the answer on this question: mongoexport JSON parsing error

我们在这个问题上找到了答案:mongoexport JSON解析错误

To resolve this error, first, we convert it to strtotime:

要解决此错误,首先,我们将其转换为strtotime:

php > echo strtotime("12/10/2012");
1355126400

Next, multiple strtotime result by 1000. This date will looks like this:

接下来,多个strtotime结果为1000.此日期将如下所示:

1355126400000

Lastly, change ISODate("2012-12-10T00:00:00.000Z") to new Date(1355126400000) in the mongoexport command.

最后,在mongoexport命令中将ISODate(“2012-12-10T00:00:00.000Z”)更改为新日期(1355126400000)。

Now, the CLI mongoexport looks like this and it works:

现在,CLI mongoexport看起来像这样,它可以工作:

mongoexport -d maindb -c Samples -f "id,file_name,d_start,d_end" -q "{'\$or' : [ { 'status' : 'FU' }, { 'status' : 'FD'} ] , 'd_end' : { '\$gte' : new  Date(1355126400000) } }" --csv -o "/home/asaj/listupdate.csv"

Note: remove space between each field names in -f or --fields option.

注意:在-f或--fields选项中删除每个字段名称之间的空格。

#2


2  

I know it has little to do with this question, but the title of this post brought it up in Google so since I was getting the exact same error I'll add an answer. Hopefully it helps someone.

我知道这与这个问题没什么关系,但是这篇文章的标题在Google上提出来,所以因为我得到完全相同的错误,我会添加一个答案。希望它可以帮助某人。

My issue was adding a MongoId query for _id to a mongoexport console command on Windows. Here's the error:

我的问题是在Windows上将_id的MongoId查询添加到mongoexport控制台命令。这是错误:

Assertion: 10340:Failure parsing JSON string near: _id

The problem ended up being that I needed to wrap the JSON query in double quotes, and the ObjectId had to be in double quotes (not single!), so I had to escape those quotes. Here's the final query that worked, for future reference:

问题最终是我需要用双引号包装JSON查询,并且ObjectId必须是双引号(不是单引号!),所以我不得不逃避这些引号。这是最终的查询,以供将来参考:

 mongoexport -u USERNAME -pPASSWORD -d DATABASE -c COLLECTION 
   --query "{_id : ObjectId(\"5148894d98981be01e000011\")}"