0

I'm new to MongoDB and am trying to track operations on my database. Based on the documentation it seems like operations like inserts should be in both the oplog and profiler, but I only see it recorded in the profiler. For context, I am making inserts in the local database in a test collection (e.g. 'local.col'), but filtering for 'local.col' only yields results in the profiler output, not the oplog.

Based on this, I'm trying to understand the differences between the two tools, as I couldn't find anything on the internet addressing when oplog doesn't log operations.

llu
  • 1
  • 1
  • https://docs.mongodb.com/manual/core/replica-set-oplog/ You can query the oplog status, and under some circumstance it might lag. –  Jan 19 '18 at 18:37

1 Answers1

0

Let's insert something..

db.getSiblingDB("local").oplog.rs.find().sort({ts:-1})

And then look what we have at oplog...

db.getSiblingDB("local").oplog.rs.find({"ns":"test.testi"}) { "ts" : Timestamp(1516437458, 2), "t" : NumberLong(80), "h" : NumberLong("8404799607288492717"), "v" : 2, "op" : "i", "ns" : "test.testi", "o" : { "_id" : ObjectId("5a62ffd1c0d303fa808617bf") } }

You can see that we have insert operation (op) "i" with namespace (ns) "test.testi" and document (o) had only object id what system automatically added to empty document.

So, oplog records only changes. Which we can see here...

db.getSiblingDB("test").testi.update({"_id" : ObjectId("5a62ffd1c0d303fa808617bf") },{$set:{"other":"second"}}) WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })

what produces...

{ "ts" : Timestamp(1516437961, 1), "t" : NumberLong(80), "h" : NumberLong("-6648566515650969093"), "v" : 2, "op" : "u", "ns" : "test.testi", "o2" : { "_id" : ObjectId("5a62ffd1c0d303fa808617bf") }, "o" : { "$set" : { "other" : "second" } } }

JJussi
  • 1,540
  • 12
  • 12