MongoExport:可以查询字段吗?

发布于 2025-01-13 09:22:26 字数 782 浏览 2 评论 0原文

我目前正在研究使用 Mongo 数据库的解决方案。 为此,我们必须使用 MongoExport。 有没有办法增强我的 MongoExport 命令以在字段上包含过滤器?

例如: -q:"{"Status": "COMPLETE"}" -f:Id,EanCode,Channels:{"$elemMatch":{"ChannelId":"Test"}

更新: 再次您好,根据评论中的建议,我添加了示例文档。

文档:

{
  "Id": "1"
  "Status": "COMPLETE",
  "EanCode": "1234567890",
  "Barcode": "100100100",
  "Name": "Test Product",
  "Channels": [
    {
      "ChannelId": "Test"
    },
    {
      "ChannelId": "Dumbeldore"
    }
  ]
}

结果:

{
  "Id": "1"
      "Status": "COMPLETE",
      "EanCode": "1234567890",
      "Channels": [
        {
          "ChannelId": "Test"
        }
      ]
}

我可以使用您建议的任何工具,可能会超出 MongoExport 的范围。 但重要的是它必须优化并导出 JSON 对象。

感谢您的关注和帮助:)

I am currently working on a solution using Mongo database.
We must use MongoExport for this one.
Is there a way to enhance my MongoExport command to include a filter on the fields?

For instance:
-q:"{"Status": "COMPLETE"}"
-f:Id,EanCode,Channels:{"$elemMatch":{"ChannelId":"Test"}

Update:
Hello again, by suggestion in the comments I am adding am example document.

Document:

{
  "Id": "1"
  "Status": "COMPLETE",
  "EanCode": "1234567890",
  "Barcode": "100100100",
  "Name": "Test Product",
  "Channels": [
    {
      "ChannelId": "Test"
    },
    {
      "ChannelId": "Dumbeldore"
    }
  ]
}

Result:

{
  "Id": "1"
      "Status": "COMPLETE",
      "EanCode": "1234567890",
      "Channels": [
        {
          "ChannelId": "Test"
        }
      ]
}

I can use any tool you suggest, might space out from the MongoExport.
But the important thing is that It must be optimized and export JSON Objects.

Thank you for your attention and help :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

习ぎ惯性依靠 2025-01-20 09:22:26

选项 1。
我认为你不能直接使用 mongoexport ,但你可以通过聚合来完成:

 echo 'db.test.aggregate([{$match:{Status:"COMPLETE","Channels.ChannelId":"Test"} },{$addFields:{Channels:{ $filter: { input: "$Channels", as: "ch", cond: {$eq:["$ch.ChannelId","Test"] }  } }} } ])' | mongo --authenticationDatabase admin  --port 27017 -u test -p xxxx --quiet > out.json

playground1

选项 2:
您通过 $out 从聚合输出到输出集合,然后进行 mongoexport。

游乐场2

Option 1.
I think you cannot do with mongoexport directly , but you can do via aggregation:

 echo 'db.test.aggregate([{$match:{Status:"COMPLETE","Channels.ChannelId":"Test"} },{$addFields:{Channels:{ $filter: { input: "$Channels", as: "ch", cond: {$eq:["$ch.ChannelId","Test"] }  } }} } ])' | mongo --authenticationDatabase admin  --port 27017 -u test -p xxxx --quiet > out.json

playground1

Option 2:
You output from aggregation to a output collection via $out and then you mongoexport.

playground2

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文