gpt4 book ai didi

mongodb - 使用查询的 MongoExport

转载 作者:可可西里 更新时间:2023-11-01 10:13:02 25 4
gpt4 key购买 nike

当我尝试从 mongoDB 中获取数据时。我能够使用此查询显示我想要实现的目标

db.sInsert.distinct(
"comments_data.comments.data.message",
{post_id: {"$eq": "28011986676" }}
)

结果在哪里

[ "Who else loves Apple ?" ]

另外,我的文档是这样的

{
"_id" : ObjectId("5a43aa19d4b45e362428e2da"),
"comments_data" : {
"id" : "28011986676_10155780942281677",
"comments" : {
"paging" : {
"cursors" : {
"after" : "WTI5dGJXVnVkRjlqZAFhKemIzSTZAN4TlRBeE5EWXlPQT09",
"before" : "WTI5dGJXVnVk4TVRZAMk56YzZANVFV4TlRBeE5EWXlPQT09"
}
},
"data" : [
{
"created_time" : "2018-01-03T21:23:47+0000",
"message" : "Poor customer care service after became the Singtel customer.I did my re contract they send acknowledgement email confirmation after no followup.I called again and remains no proper response and action extremely worst customer care service.",
"from" : {
"name" : "Sundararaju G",
"id" : "1020391"
},
"id" : "10155780942281677_10155811924116677"
}
]
}
},
"post_id" : "28011986676_10155780942281677",
"post_message" : "\"Singtel TV celebrated our 10th birthday with 10 awesome experiences for our customers! Each of our winners won a trip of a lifetime - from attending the Emmy Awards, getting a magical princess treatment at Disneyland, to catching a Premier League game live in London! We thank all our customers for your support and we look forward to more great years to come!\"",
"reactions_data" : {
"reactions" : {
"paging" : {
"cursors" : {
"after" : "TVRBd01EQXpNVEF5T1Rje4TXc9PQZDZD",
"before" : "TVRjNE56TTBBek56a3hNek14TWc9PQZDZD"
},
"next" : "https://graph.facebook.com/v2.7/280119866761677/reactions?access_token=EAA"
},
"data" : [
{
"type" : "ANGRY",
"id" : "1020573391",
"name" : "Sundararaju Gh"
},
{
"type" : "LIKE",
"id" : "64721496",
"name" : "Zhiang Xian"
}
]
},
"id" : "28011986676_102281677"
}
}

但是当我尝试将其导出时,下面有这句话。我遇到错误

mongoexport --db sDB --collection sInsert --query '{"post_id":{$gte:28011986676}}',{ comments_data.comments.data.message}' --out test.json

错误信息在哪里

2018-01-29T19:56:31.442+0800    too many positional arguments: [comments_data.comments.data.message}']
2018-01-29T19:56:31.526+0800 try 'mongoexport --help' for more information

请问,是否可以导出我想要实现的内容,如我如何在 mongodb 中显示?

最佳答案

您的 mongoexport 命令的这一部分 ...

--query '{"post_id":{$gte:28011986676}}',{ comments_data.comments.data.message}'

... 建议您尝试使用 query 参数指定过滤器 投影。根据the docs query 参数:

Provides a JSON document as a query that optionally limits the documents returned in the export.

所以,这仅适用于过滤器。

您可以使用 fields 参数将输出限制为特定字段。来自 the docs :

Specifies a field or fields to include in the export. Use a comma separated list of fields to specify multiple fields.

因此,您的 mongoexport 命令应该是:

mongoexport --db sDB --collection sInsert --query '{"post_id":{$gte:28011986676}}' --fields "comments_data.comments.data.message" --out test.json

但是,由于您选择了 JSON 输出格式,因此以下内容(来自文档)是相关的:

For JSON output formats, mongoexport includes only the specified field(s) and the _id field, and if the specified field(s) is a field within a sub-document, the mongoexport includes the sub-document with all its fields, not just the specified field within the document.

由于您尝试使用 JSON 输出格式从子文档中选择特定字段,mongoexport 将包含“子文档及其所有字段,而不是只是文档中指定的字段。

这听起来很像 earlier question from you 中提出的问题.

关于mongodb - 使用查询的 MongoExport,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48500880/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com