Skip to content

Instantly share code, notes, and snippets.

@gscattolin
Last active August 15, 2016 05:38
Show Gist options
  • Save gscattolin/d962c8ef53aeeea3c995f06ec556b66d to your computer and use it in GitHub Desktop.
Save gscattolin/d962c8ef53aeeea3c995f06ec556b66d to your computer and use it in GitHub Desktop.
MongoDb Most common commands
db.audit.remove({"reqTime" : { $lt : new Date('01/01/2016').getTime()}}) #remove everything is older than (bad performance)
db.audit.find().sort({"createdAt" : -1}).limit(1) #get latest created
db.collection.stats() #info about collection
export collection mongo in cvs file
mongoexport -h host -d dbname -c collectionname --type=csv -f name,side,type,field --out ~/export20160426.csv
db.fs.files.aggregate([{$group: {_id: "$contentType", total : { $sum: 1 }}}]) # count type on FS Grid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment