最大的BSON文档的大小是16兆,超过这个大小需要使用GrdiFS API
文档需要_id域作为主键,如果没有指定_id域,那么会使用ObjectIds 作为默认值。
对于WiredTiger storage engine readConcern选项允许选择读的隔离级别,可以使用majority,这个级别可以读写入到replica set大部分成员中的数据,不可回滚。
MMAPv1 存储引擎,只能指定local级别
默认情况下mongodb使用local级别,不保证读的数据不会回滚。
level Description
“local”
Default. The query returns the instance’s most recent copy of data. Provides no guarantee that the data has been written to a majority of the replica set members.
“majority”
The query returns the instance’s most recent copy of data confirmed as written to a majority of members in the replica set.
To use a read concern level of “majority”, you must use the WiredTiger storage engine and start the mongod instances with the –enableMajorityReadConcern command line option (or the replication.enableMajorityReadConcern setting if using a configuration file).
Only replica sets using protocol version 1 support “majority” read concern. Replica sets running protocol version 0 do not support “majority” read concern.
To ensure that a single thread can read its own writes, use “majority” read concern and “majority” write concern against the primary of the replica set.
mongodb中一个写操作,如果这个写操作修改了一个记录,那么是原子操作,如果这个写操作修改了几个记录,那么对每个记录来说是原子操作,但是整体上不是一个原子操作,可以使用
isolated操作符来讲这样的写操作做为一个原子操作。
isolated does not work with sharded clusters.
一个隔离的写操作不会提供“all-or-nothing”的原子性,不会回滚遇到错误之前的所有的改变。
并发控制,mongodb中使用下面2个方法:
1创建唯一索引
2Another approach is to specify the expected current value of a field in the query predicate for the write operations.
Read uncommitted is the default isolation level and applies to mongod standalone instances as well as to replica sets and sharded clusters.