0

我是 MongoDB 新手,正在尝试跟踪我的数据库上的操作。根据文档,插入之类的操作似乎应该在 oplog 和分析器中,但我只看到它记录在分析器中。对于上下文,我在测试集合(例如'local.col')中的本地数据库中进行插入,但过滤'local.col'只会产生分析器输出的结果,而不是oplog。

基于此,我试图了解这两个工具之间的区别,因为当 oplog 不记录操作时,我在 Internet 寻址上找不到任何东西。

4

1 回答 1

0

让我们插入一些东西..

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

然后看看我们在 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") } }

你可以看到我们有插入操作(op)“i”和命名空间(ns)“test.testi”和文档(o)只有系统自动添加到空文档的对象id。

所以,oplog 只记录变化。我们可以在这里看到...

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

什么产生...

{ "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" } } }

于 2018-01-20T08:48:12.857 回答