Mongodb: Ravikumer Maddi
Mongodb: Ravikumer Maddi
Mongodb: Ravikumer Maddi
Ravikumer Maddi
Object Id:
ObjectId is a 12-byte BSON type, constructed using:
Tab-1
MongDB
No Meta data What you need to keep
you can keep, no need to obey any
structure.
db.help()
db.mycoll.help()
sh.help()
rs.help()
help admin
help connect
help keys
help misc
help mr
help on db methods
help on collection methods
sharding helpers
replica set helpers
administrative help
connecting to a db help
key shortcuts
misc things to know
mapreduce
Continue
show dbs
show database names
show collections
show collections in current database
show users
show users in current database
show profile
show most recent system.profile entries with time >= 1ms
show logs
show the accessible logger names
show log [name]
prints out the last segment of log in memory, 'global' is default
use <db_name>
set current database
db.foo.find()
list objects in collection foo
db.foo.find( { a : 1 } )
list objects in foo where a == 1
it
result of the last line evaluated; use to further iterate
DBQuery.shellBatchSize = x set default number of items to display on shell
exit
quit the mongo shell
Create replica
cd c:\data
md db1
md db2
md db3
cd c:\mongodb\bin
@REM Primary
start "a" mongod --dbpath ./db2 -port 30000 --replSet "demo"
@REN Secibdart
start "b" mongod --dbpath ./db2 -port 40000 --replSet "demo"
@REN Arvuter
start "c" mongod --dbpath ./db2 -port 50000 --replSet "demo"
Notedown:
Then it will open three consoles for three replicas.
then to connect to perticular replica run:
mongo --path 30000
Failover
. Close primary console(a) and
observer.
. Secondary becomes as
Primary because primary was
closed.
. And you can find the data and.
The port was 40000(Seconday).
Ie. Seconday become as Primay.
To recreate the primary:
. Come out of mongo,
. Run the same command that
you run last time to start.
. Then again start mongo with
which replica you want.
--eval
Commands:
> mongo localhost/admin --eval
"db.runcommand({logRotate:1})"
> mongo localhost/admin --eval
"printjson(db.runcommand({logR
otate:1}))"
saveDB.js
DB.prototype.dropDatabase = function(){
print("Don't do it man! ");
}
db.dropDatabase = DB.prototype.dropDatabase
mongo saveDB.js shell
Try to delete
> db.dropDatabase()
MongoRC.js
This is the file(.mongorc.js) to automatically recognize by the mongo and run
after mongo shell(mongo) started and no need to maintain in separate .js
files and remember it.
It should be c:\users\<yours>\.mongorc.js
See here it is.
mongo --norc
If you start shell with above command it
.mongorc.js dont run after your shell started.