Tag Archives: mongodb

After reboot of your master, slave and master switched their roles and you want to switch back them:
login to current master and make:

1
2
3
4
cfg = rs.conf()
cfg.members[0].priority = 1
cfg.members[1].priority = 0.5
rs.reconfig(cfg)

after «cfg = rs.conf ()» you'll see config, change priority for master (set bigger number) and for slave (set lower number).

mongodb: minimal howto

Connect:
mongo --host 10.0.0.1 dbname // host and dbname

Show all databases:
> show dbs

Connect to specific db:
> use dbname

Show all collections (this is tables in the mongo's naming):
> show collections

Show contents of collection:
> db.collection_name.find ().pretty () // db — isn't database name, this is a KEY word, collection_name — is a name of collection which you got with previous command.

Make a select query:
> db.comments.find ({'creatorId':Number (72116967665828320)}).pretty () // select all messages from collection «comments» where field «creatorId» = Number (72116967665828320), type Number very important.