0

Say I have an entry in the inventory collection that looks like

{ _id: 1, item: "polarizing_filter", tags: [ "electronics", "camera" ]}

and I issue the command

db.inventory.update(
   { _id: 1 },
   { $addToSet: { tags: "accessories" } }
)

I have an oplog tailer, and would like to know that, specifically, "accessories" has been added to this document's tags field. As far as I can tell, the oplog always normalizes commands to use $set and $unset to maintain idempotency. In this case, the field of the entry describing the update would show something like

{$set : { tags : ["electronics", "camera", "accessories"] } }

which makes it impossible to know which tags were actually added by this update. Is there anyway to do this? I'm also curious about the analogous case in which fields are modified through deletion, e.g. through $pull. Solutions outside of the realm of an oplog tailer are welcome, as well as pointers to documentation of this command normalization process - I can't find it.

Thanks!

BobbyPin
  • 59
  • 6
  • From the Oplog? No. Can you do it on atomic update responses? To some degree, being the "difference" between what was submitted and what was returned. But that of course does not consider if "something else" modified the document from "what you think" was there to the new addition. The point of "atomic updates" is that you really should not care. So you probably should reconsider your process and why you "think" you need this information. Because you likely don't need it at all. – Neil Lunn Oct 25 '17 at 07:25
  • This information is in fact needed. There is another system component that would like to perform updates as certain fields are modified, with the updates depending on the particular additions/deletions to these fields. My goal was to do this without state, as looking up/maintaining the state of these documents is far too inefficient for my use case. – BobbyPin Oct 26 '17 at 22:54

0 Answers0