MongoDB学习记录
Replication Set Oplog:所有的数据库的写操作记录在 oplog collection。Replica set 的secondary服务通过 oplog来进行同步。
其他客户端能够在写的客户端写操作返回之前就独到写的数据。客户端能够独到后续被 rollback的写数据。
PriorityElectionHidden MemberDelayed Replic Set Member: 具体延时时间受 oplog的size 限制。必须比 oplog size要小。不能再sharding cluster里面使用。Journaling:保证断电安全Rollback when failover: 可以使用 w: majority write concern避免产生failover 时的rollback。会保证客户端只有在该操作已经同步给其他的 secondary服务器的时候,才会收到操作完毕的返回。db.products.insert({ item: "envelopes" , qty : 100 , type: "Clasp" },{ writeConcern: { w: 2 , wtimeout: 5000 } })
C++Driver安装 Legacy版本:scons 、python、 boost 1.4.9以上Scons需要python2.4 之后的版本,而且只支持 32位的版本。否则会提示无法找到 python的注册表信息。安装的时候必须使用管理员权限启动。安装完毕后需要在 path中添加c:\pythonxx\scripts 。Scons.bat在该路径下。Boost
下载完毕后使用bootstrap.bat进行安装,然后使用 ./b2进行编译使用 link=static runtime-link=static来编译出来mt-sgd 的版本。使用 address-model=64来编译64 位版本。
使用 scons install –cpppath=”boost 库地址” –libpath=”boost库地址\stage\lib” –msvc_host-arch=“x86_64”来进行编译。增加 —dbg=[on\off]参数可以指定是debug或者 release版本
Include\mongo\client\autolib.h 会自动的链接对应的 lib库。Debug 链接xxx-sgd.lib, release链接 xxx-s.lib
Mongo Shell 参考 manual 3.0. -> refrence -> mongo Shell Methods 。普及一下概念:每一条存储的记录叫做一个 document。Document是存储在collection 里面的。Collection会在insert 的时候自动创建。一个 Mongo服务器启动后是一个
数据库。
Collection存在capped 、index、 autoindexId。操作和普通数据库差不多 insert、update 、find(select)、 remove(delete)Update有$set 、replace、 multi、upsert 几种模式。
Sharding模式 使用 mongo就是奔着分布式来的。Sharding模式需要 3个模块组成:router、 Shard、Config Server。
C++ mongo-cxx-driver-legacy-1.0.4代码阅读 Query:std::auto_ptr
返回DBClientConnection::query(const std::string &ns // 操作的collection, Query query // 查询BSON语句, int nToReturn // 选择返回多少结果 document, int nToSkip // 选择从第几个开始返回, const BSONObj *fieldsToReturn // 过滤要返回的列, int queryOptions // dbclientinterface.h QueryOptions, int batchSize )
QueryOptions:QueryOption_CursorTailable:QueryOption_SlaveOk:只要从副本查找(无需最新 )QueryOption_OplogReplay:findstart?QueryOption_NoCursorTimeout :服务器一般会对空闲的cursor进行 times out,以回收内存。设置了可以避免 cursor被回收。QueryOption_AwaitData:与 QueryOption_CursorTailable一起使用。QueryOption_Exhaust:QueryOption_PartialResults :QueryOption_AllSupported:
Update:void DBClientBase::update(const string & ns // collection, Query query // 更新过滤条件, BSONObj obj // 更新内容, bool upsert // 不存在过滤内容是否插入, bool multi // 是否更新多条, const WriteConcern* wc )
Remove:void DBClientBase::remove(const string & ns, Query obj, bool justOne, const WriteConcern* wc )
Insert:void DBClientBase::insert(const string & ns, BSONObj obj, int flags, const WriteConcern* wc )InsertOptions:InsertOption_ContinueOnError:在multiinsert的时候,在发生错误后继续插入
|