valegrajales
4/10/2014 - 4:41 PM

Commands for MongoDB

Commands for MongoDB

## Create a new collection/database using data from other collection/database
db.tweets.find({place: somewhere, lang: somelang}).forEach(function(d){ db.getSiblingDB('database')['collection'].insert(d); })

## Inverse sort and limit
db.tweets.find().sort({created_at:-1}).limit(20)

## Find number of not null elements
db.tweets.find({'longitude': {$exists: 1}}).count()

## Find not null document with condition
db.tweets.find({rank_lexicon_positive: {$exists: true}})

## Find group by type in this case for collection entities
db.entities.group({key: {type: 1}, cond: {}, reduce: function(curr, result){}, initial: {}})