查询MongoDB删除触发器 [英] Query on MongoDB Delete Triggers

查看:93
本文介绍了查询MongoDB删除触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是MongoDB的新手。

I am a newbie for MongoDB.

请帮我解决以下问题:

我正在使用oplogs为MongoDB操作添加触发器。在进行插入/更新操作时,我收到有关集合中添加/更新的所有字段的完整信息。

I am using oplogs for adding Triggers for MongoDB operation. On doing insert/update operations, I receive the complete information about all fields added/updated in the collection.

我的问题是:

当我在MongoDB中删除操作时,收到的oplog触发器只包含object_id。

When I do delete operations in MongoDB, the oplog triggers received contains ONLY the object_id.

请有人指出我可以收到的一些例子所有字段中的完整信息 - 触发器中已删除的行。

Can somebody please point out to some example where I can receive complete information in all fields - for the deleted row in the trigger.

谢谢

推荐答案

你必须通过它的ObjectID获取该文档,这在当前节点上是不可能的,因为当你收到 oplog 时从 oplog 删除操作,文档消失了。我相信这意味着你有两个选择:

You have to fetch that document by its ObjectID, which will not be possible on the current node you are tailing the oplog from because by the time you have received the delete operation from the oplog, the document is gone. Which I believe means you have two choices:


  1. 确保所有删除之前都有更新操作,允许您查看文档字段你需要在删除之前(当然这会使删除更加昂贵)

  2. 使用 slave delay 然后查​​询该节点以查找已删除的文档(直接或使用标签)。

  1. Make sure that all deletes are preceded by an update operation which allows you to see the document fields you require prior to deletion (this will make deletes more expensive of course)
  2. Run a secondary with a slave delay and then query that node for the document that has been deleted (either directly or by using tags).

对于数字2,问题是延迟时间足以保证您可以获取文档并且足够短以确保您获得文档的最新版本。除非您将版本添加到文档作为检查(然后类似于选项1,您可能希望在删除之前更新版本),这本质上必须是一个乐观的,尽力而为的解决方案。

For number 2, the issue is having a delay that is long enough to guarantee that you can fetch the document and short enough to make sure you are getting an up to date version of the document. Unless you add versioning to the document as a check (which is then getting similar to option 1, you would likely want to update the version before deleting), this would have to be essentially an optimistic, best efforts solution.

这篇关于查询MongoDB删除触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆