当前位置:  开发笔记 > 编程语言 > 正文

关于mongodb 的Oplog

mongodb的Replication是通过一个日志来存储写操作的,这个日志就叫做Oplog。在默认情况下,对于64位的mongodb,oplogs都相当大-可能是5%的磁盘空间。通常而言,这是一种合理的设置。可以通过mongod--oplogSize来改变Oplog的日志大

mongodb的Replication是通过一个日志来存储写操作的,这个日志就叫做Oplog。

在默认情况下,对于64位的mongodb,oplogs都相当大-可能是5%的磁盘空间。通常而言,这是一种合理的设置。可以通过mongod --oplogSize来改变Oplog的日志大小。

 

Oplog的collectio为:

local.oplog.$main for master/slave replication;

local.oplog.rs for replica sets

如 master/slave replication:

> use local               
switched to db local
> db.oplog.$main.help()
DBCollection help
        db.oplog.$main.find().help() - show DBCursor help
        db.oplog.$main.count()
        db.oplog.$main.dataSize()
        db.oplog.$main.distinct( key ) - eg. db.oplog.$main.distinct( 'x' )
        db.oplog.$main.drop() drop the collection
        db.oplog.$main.dropIndex(name)
        db.oplog.$main.dropIndexes()
        db.oplog.$main.ensureIndex(keypattern,options) - options should be an object with these possible fields: name, unique, dropDups
        db.oplog.$main.reIndex()
        db.oplog.$main.find( [query] , [fields]) - first parameter is an optional query filter. second parameter is optional set of fields to return.
                                           e.g. db.oplog.$main.find( { x : 77 } , { name : 1 , x : 1 } )
        db.oplog.$main.find(...).count()
        db.oplog.$main.find(...).limit(n)
        db.oplog.$main.find(...).skip(n)
        db.oplog.$main.find(...).sort(...)
        db.oplog.$main.findOne([query])
        db.oplog.$main.findAndModify( { update : ... , remove : bool [, query: {}, sort: {}, 'new': false] } )
        db.oplog.$main.getDB() get DB object associated with collection
        db.oplog.$main.getIndexes()
        db.oplog.$main.group( { key : ..., initial: ..., reduce : ...[, cond: ...] } )
        db.oplog.$main.mapReduce( mapFunction , reduceFunction , )
        db.oplog.$main.remove(query)
        db.oplog.$main.renameCollection( newName , ) renames the collection.
        db.oplog.$main.runCommand( name , ) runs a db command with the given name where the first param is the collection name
        db.oplog.$main.save(obj)
        db.oplog.$main.stats()
        db.oplog.$main.storageSize() - includes free space allocated to this collection
        db.oplog.$main.totalIndexSize() - size in bytes of all the indexes
        db.oplog.$main.totalSize() - storage allocated for all data and indexes
        db.oplog.$main.update(query, object[, upsert_bool, multi_bool])
        db.oplog.$main.validate() - SLOW
        db.oplog.$main.getShardVersion() - only for use with sharding
> db.oplog.$main.find()
{ "ts" : { "t" : 1294582140000, "i" : 14 }, "op" : "d", "ns" : "mixi_top_city.building_90", "b" : true, "o" : { "_id" : "6380690_441_30_29" } }
{ "ts" : { "t" : 1294582140000, "i" : 15 }, "op" : "i", "ns" : "mixi_top_city.building_90", "o" : { "_id" : "6380690_441_24_24", "uid" : "6380690", "x" : 24, "y" : 24, "pos" : 1, "btime" : 1294154452, "ntime" : 1294154452, "bid" : 71, "extprop" : 0, "status" : 0, "ucid" : 441 } }
{ "ts" : { "t" : 1294582140000, "i" : 16 }, "op" : "u", "ns" : "mixi_top_city.building_64", "o2" : { "_id" : "16702364_459_14_14" }, "o" : { "$set" : { "status" : 1 } } }
{ "ts" : { "t" : 1294582140000, "i" : 17 }, "op" : "u", "ns" : "mixi_top_city.building_08", "o2" : { "_id" : "6223408_391_30_28" }, "o" : { "$set" : { "ntime" : 1294582321 } } }
{ "ts" : { "t" : 1294582140000, "i" : 18 }, "op" : "u", "ns" : "mixi_top_city.building_03", "o2" : { "_id" : "9882403_353_28_20" }, "o" : { "$set" : { "ntime" : 1294600141 } } }
{ "ts" : { "t" : 1294582140000, "i" : 19 }, "op" : "u", "ns" : "mixi_top_city.building_24", "o2" : { "_id" : "4162924_365_32_28" }, "o" : { "$set" : { "ntime" : 1294582321 } } }
{ "ts" : { "t" : 1294582141000, "i" : 1 }, "op" : "u", "ns" : "mixi_top_city.building_49", "o2" : { "_id" : "32797749_285_28_30" }, "o" : { "$set" : { "ntime" : 1294583341 } } }
{ "ts" : { "t" : 1294582141000, "i" : 2 }, "op" : "u", "ns" : "mixi_top_city.building_50", "o2" : { "_id" : "33768850_425_28_32" }, "o" : { "$set" : { "ntime" : 1294582561 } } }
{ "ts" : { "t" : 1294582141000, "i" : 3 }, "op" : "u", "ns" : "mixi_top_city.building_35", "o2" : { "_id" : "28235635_333_28_36" }, "o" : { "$set" : { "ntime" : 1294582741 } } }
{ "ts" : { "t" : 1294582141000, "i" : 4 }, "op" : "u", "ns" : "mixi_top_city.building_04", "o2" : { "_id" : "25178304_3_32_28" }, "o" : { "$set" : { "ntime" : 1294594141 } } }
{ "ts" : { "t" : 1294582141000, "i" : 5 }, "op" : "u", "ns" : "mixi_top_city.building_18", "o2" : { "_id" : "7304918_445_32_26" }, "o" : { "$set" : { "ntime" : 1294582321 } } }
{ "ts" : { "t" : 1294582141000, "i" : 6 }, "op" : "u", "ns" : "mixi_top_city.building_93", "o2" : { "_id" : "5003293_453_20_24" }, "o" : { "$set" : { "status" : 1 } } }
{ "ts" : { "t" : 1294582141000, "i" : 7 }, "op" : "u", "ns" : "mixi_top_city.building_59", "o2" : { "_id" : "19601459_485_28_30" }, "o" : { "$set" : { "ntime" : 1294582741 } } }
{ "ts" : { "t" : 1294582141000, "i" : 8 }, "op" : "u", "ns" : "mixi_top_city.building_47", "o2" : { "_id" : "23744647_273_22_46" }, "o" : { "$set" : { "ntime" : 1294582741 } } }

推荐阅读
臭小子
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有