Tag

MongoDB

8 posts

MongoDB (from "humongous") is an open-source document database, and the leading NoSQL database.

Code

Index of Using MongoDB

In this post, I am going to list a set of page as navigation, so that we can use MongoDB easier.

Code

Mongodb 按键值去重

MongoDB建立index,可以设置为unique.若在之前有重复的键值,那么我们必须要去除掉重复的.

若我们使用的是原生的mongo且版本小于3.0,则unique为true外,外加参数dropDups为true即可.但除此之外,在mongo3.0+,tokumx,我们只能手工搞定.

Code

格式化MongoDB的输出

通过mongo自带的命令行进入后,db.coll_name.findOne(),可以发现mongo返回的数据是被format过的,看起来各种爽。但若你抽一下,改用db.coll_name.find(),瞬间弥漫而来的是各种unformatted数据,根本没法看。其实我们很容易就可以调整让它显示地更加漂亮。 现在有两种方法可以做到这点。

Code

MongoDB Replica Sets的配置

MongoDB是一种很不错的NoSQL数据库,数据库存储基于BSON,一种JSON的变种。在使用的时候,有时候我们dump某个单个的collection/db作为备份的时候,往往会连累到整库都访问困难。集群有时候果断是个不错的选择。

MongoDB的存储是Replica,有三种角色如下:

Diagram of a replica set that consists of a primary, a secondary, and an arbiter.