http://www.mongodb.org/display/DOCS/Replica+Sets+-+Oplog
myset:PRIMARY> db.mycoll.insert({x:1})

myset:PRIMARY> db.mycoll.update({x:1}, {$set : {y:1}})

myset:PRIMARY> db.mycoll.update({x:2}, {$set : {y:1}}, true)

myset:PRIMARY> db.mycoll.remove({x:1})

myset:PRIMARY> db.mycoll.find()

{ "_id" : ObjectId("4def8e5fb07da951204c60e0"), "x" : 1, "y" : 1 }

{ "_id" : ObjectId("4def8e5fd60f868d9ea77776"), "x" : 2, "y" : 1 }
myset:PRIMARY> use local

myset:PRIMARY> db.oplog.rs.find().sort({$natural:-1})

{ "ts" : { "t" : 1307545183000, "i" : 4 }, "h" : NumberLong("-1214445074120755058"), "op" : "d",

"ns" : "test.mycoll", "b" : true, "o" : { "_id" : ObjectId("4def8e5fb07da951204c60e0") } }



{ "ts" : { "t" : 1307545183000, "i" : 3 }, "h" : NumberLong("296197708926251535"), "op" : "i",

"ns" : "test.mycoll", "o" : { "_id" : ObjectId("4def8e5fd60f868d9ea77776"), "x" : 2, "y" : 1 } }



{ "ts" : { "t" : 1307545183000, "i" : 2 }, "h" : NumberLong("6923456793495821492"), "op" : "u",

"ns" : "test.mycoll", "o2" : { "_id" : ObjectId("4def8e5fb07da951204c60e0") }, "o" : { "$set" :

{ "y" : 1 } } }



{ "ts" : { "t" : 1307545183000, "i" : 1 }, "h" : NumberLong("-4148240362977057242"), "op" : "i",

"ns" : "test.mycoll", "o" : { "_id" : ObjectId("4def8e5fb07da951204c60e0"), "x" : 1 } }

...
Wed Jun   8 23:53:38 [conn6] getmore local.oplog.rs cid:3687673685314762755 getMore:

{ ts: { $gte: new Date(5615858237044687812) } }   bytes:20 nreturned:0 3022ms



Wed Jun   8 23:53:38 [conn8] getmore local.oplog.rs cid:9178181051262829411 getMore:

{ ts: { $gte: new Date(5615858237044687812) } }   bytes:20 nreturned:0 3046ms



Wed Jun   8 23:53:41 [conn8] getmore local.oplog.rs cid:9178181051262829411 getMore:

{ ts: { $gte: new Date(5615858237044687812) } }   bytes:20 nreturned:0 3041ms



Wed Jun   8 23:53:41 [conn6] getmore local.oplog.rs cid:3687673685314762755 getMore:

{ ts: { $gte: new Date(5615858237044687812) } }   bytes:20 nreturned:0 3043ms

...
myset:SECONDARY> db.oplog.rs.find().sort({$natural:-1})

{ "ts" : { "t" : 1307545183000, "i" : 4 }, "h" : NumberLong("-1214445074120755058"), "op" : "d",

"ns" : "test.mycoll", "b" : true, "o" : { "_id" : ObjectId("4def8e5fb07da951204c60e0") } }



{ "ts" : { "t" : 1307545183000, "i" : 3 }, "h" : NumberLong("296197708926251535"), "op" : "i",

"ns" : "test.mycoll", "o" : { "_id" : ObjectId("4def8e5fd60f868d9ea77776"), "x" : 2, "y" : 1 } }



{ "ts" : { "t" : 1307545183000, "i" : 2 }, "h" : NumberLong("6923456793495821492"), "op" : "u",

"ns" : "test.mycoll", "o2" : { "_id" : ObjectId("4def8e5fb07da951204c60e0") }, "o" : { "$set" :

{ "y" : 1 } } }



{ "ts" : { "t" : 1307545183000, "i" : 1 }, "h" : NumberLong("-4148240362977057242"), "op" : "i",

"ns" : "test.mycoll", "o" : { "_id" : ObjectId("4def8e5fb07da951204c60e0"), "x" : 1 } }

...
MongoDB Oplog入門
MongoDB Oplog入門

MongoDB Oplog入門

  • 18.
  • 19.
    myset:PRIMARY> db.mycoll.insert({x:1}) myset:PRIMARY> db.mycoll.update({x:1},{$set : {y:1}}) myset:PRIMARY> db.mycoll.update({x:2}, {$set : {y:1}}, true) myset:PRIMARY> db.mycoll.remove({x:1}) myset:PRIMARY> db.mycoll.find() { "_id" : ObjectId("4def8e5fb07da951204c60e0"), "x" : 1, "y" : 1 } { "_id" : ObjectId("4def8e5fd60f868d9ea77776"), "x" : 2, "y" : 1 }
  • 20.
    myset:PRIMARY> use local myset:PRIMARY>db.oplog.rs.find().sort({$natural:-1}) { "ts" : { "t" : 1307545183000, "i" : 4 }, "h" : NumberLong("-1214445074120755058"), "op" : "d", "ns" : "test.mycoll", "b" : true, "o" : { "_id" : ObjectId("4def8e5fb07da951204c60e0") } } { "ts" : { "t" : 1307545183000, "i" : 3 }, "h" : NumberLong("296197708926251535"), "op" : "i", "ns" : "test.mycoll", "o" : { "_id" : ObjectId("4def8e5fd60f868d9ea77776"), "x" : 2, "y" : 1 } } { "ts" : { "t" : 1307545183000, "i" : 2 }, "h" : NumberLong("6923456793495821492"), "op" : "u", "ns" : "test.mycoll", "o2" : { "_id" : ObjectId("4def8e5fb07da951204c60e0") }, "o" : { "$set" : { "y" : 1 } } } { "ts" : { "t" : 1307545183000, "i" : 1 }, "h" : NumberLong("-4148240362977057242"), "op" : "i", "ns" : "test.mycoll", "o" : { "_id" : ObjectId("4def8e5fb07da951204c60e0"), "x" : 1 } } ...
  • 21.
    Wed Jun 8 23:53:38 [conn6] getmore local.oplog.rs cid:3687673685314762755 getMore: { ts: { $gte: new Date(5615858237044687812) } } bytes:20 nreturned:0 3022ms Wed Jun 8 23:53:38 [conn8] getmore local.oplog.rs cid:9178181051262829411 getMore: { ts: { $gte: new Date(5615858237044687812) } } bytes:20 nreturned:0 3046ms Wed Jun 8 23:53:41 [conn8] getmore local.oplog.rs cid:9178181051262829411 getMore: { ts: { $gte: new Date(5615858237044687812) } } bytes:20 nreturned:0 3041ms Wed Jun 8 23:53:41 [conn6] getmore local.oplog.rs cid:3687673685314762755 getMore: { ts: { $gte: new Date(5615858237044687812) } } bytes:20 nreturned:0 3043ms ...
  • 22.
    myset:SECONDARY> db.oplog.rs.find().sort({$natural:-1}) { "ts": { "t" : 1307545183000, "i" : 4 }, "h" : NumberLong("-1214445074120755058"), "op" : "d", "ns" : "test.mycoll", "b" : true, "o" : { "_id" : ObjectId("4def8e5fb07da951204c60e0") } } { "ts" : { "t" : 1307545183000, "i" : 3 }, "h" : NumberLong("296197708926251535"), "op" : "i", "ns" : "test.mycoll", "o" : { "_id" : ObjectId("4def8e5fd60f868d9ea77776"), "x" : 2, "y" : 1 } } { "ts" : { "t" : 1307545183000, "i" : 2 }, "h" : NumberLong("6923456793495821492"), "op" : "u", "ns" : "test.mycoll", "o2" : { "_id" : ObjectId("4def8e5fb07da951204c60e0") }, "o" : { "$set" : { "y" : 1 } } } { "ts" : { "t" : 1307545183000, "i" : 1 }, "h" : NumberLong("-4148240362977057242"), "op" : "i", "ns" : "test.mycoll", "o" : { "_id" : ObjectId("4def8e5fb07da951204c60e0"), "x" : 1 } } ...