Thursday, May 5, 2016

MongoDB cheat sheet

To run mongodb do
>mongod
This will start the deamon.

Then to query the DB start the client by
>mongo
 To use a DB do
use

To see the databases do
show databases

You can see the collections in a database after opening that database by
show collections

Collections correspond to Tables in mysql.

db.collection.find({key:value})

can be used to query the DB. If you want to perform "like" queries do
db.collection.find({"my key": /term/})

Do not use quotes around term in the previous example to perform like queries. If you do, then it will be an exact match.

This will not work within pymongo and you need to use $regex directive for this.
db["mycollection"].find({"key":{"$regex":"%s" % query}})

You can use count do count the number of matching records.
db.collection.count({key:value})



Continuously monitor GPU usage

 For nvidia GPUs do the follwing: nvidia-smi -l 1