MongoDB学习记录


MongoDB学习记录

Replication Set

Oplog: 所有的数据库的写操作记录在 oplog collection Replica set secondary 服务通过 oplog 来进行同步。

其他客户端能够在写的客户端写操作返回之前就独到写的数据。
客户端能够独到后续被 rollback 的写数据。

Priority
Election
Hidden Member
Delayed 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
具体可以参考: http://docs.mongodb.org/manual/tutorial/deploy-shard-cluster/

C++ mongo-cxx-driver-legacy-1.0.4代码阅读

Query:
std::auto_ptr<DBClientCursor> 返回
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_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 的时候,在发生错误后继续插入
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值