0

我们需要将我们的 nodejs 应用程序日志保存为 MongoDB 中的记录。我们应该创建的大多数记录,但有些记录只需要更新。

我们想使用 Fluentd。我看到它可以选择将日志插入 mongo,但我找不到更新现有记录的方法。

有没有办法做到这一点?

这是我当前的 td-agent.conf(仍在开发中):

<match mongo.*>
  @type mongo
  host localhost
  port 27017
  database my-db

  # Set 'tag_mapped' if you want to use tag mapped mode.
  tag_mapped

  # If the tag is "mongo.foo", then the prefix "mongo." is removed.
  # The inserted collection name is "foo".
  remove_tag_prefix mongo.

  # This configuration is used if the tag is not found. The default is 'untagged'.
  collection misc
</match>
4

1 回答 1

1

查看 fluentd mongo 插件的文档代码,它似乎不支持更新/更新操作。

目前,它仅在执行insert_many操作。

get_collection(database, collection, @collection_options).insert_many(records)

https://github.com/fluent/fluent-plugin-mongo/blob/master/lib/fluent/plugin/out_mongo.rb#L265

update_many一种选择是使用(或批量更新插入)操作在此存储库上创建功能请求或拉取请求,但这需要您在每个文档插入中发送更新字段。


更新- 任何替代工具?

我可以想到logstash,但即使它也打开了一堆功能请求以支持对MongoDB的更新/更新。

https://github.com/logstash-plugins/logstash-output-mongodb/issues/16

当您检查上述链接注释时,建议您通常不希望执行更新操作的日志存储。

https://engineering.linkedin.com/distributed-systems/log-what-every-software-engineer-should-know-about-real-time-datas-unifying

我想说首先重新审视您更新日志方法的设计,否则创建一个可以执行更新操作的自定义应用程序(Java、NodeJS、Python 或 .NET Core)(替换 fluentd 或从 fluentd 传播到自定义应用程序到 mongodb)。

于 2019-05-05T17:42:02.270 回答