码迷,mamicode.com
首页 > 数据库 > 详细

MongoDB学习记录

时间:2015-09-18 13:56:19      阅读:286      评论:0      收藏:0      [点我收藏+]

标签:


MongoDB学习记录

Replication Set

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

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

Priority
Election
Hidden Member
Delayed Replic Set Member: 具体延时时间受 oplogsize 限制。必须比 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
操作和普通数据库差不多 insertupdate find(select) remove(delete)
Update$set replace multiupsert 几种模式。


Sharding模式

使用 mongo就是奔着分布式来的。Sharding模式需要 3个模块组成:router ShardConfig Server

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的时候,在发生错误后继续插入

版权声明:本文为博主原创文章,未经博主允许不得转载。博主联系方式:skydog_forstore@hotmail.com。

MongoDB学习记录

标签:

原文地址:http://blog.csdn.net/heartrude/article/details/48544517

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!