Skip to content

Instantly share code, notes, and snippets.

View henricavalcante's full-sized avatar
🏠
Working from home

Henri Cavalcante henricavalcante

🏠
Working from home
View GitHub Profile
@henricavalcante
henricavalcante / ex.js
Created July 5, 2015 13:22
Express allow cross domain
app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
next();
});

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
$ mongostat
insert query update delete getmore command flushes mapped vsize res faults idx miss % qr|qw ar|aw netIn netOut conn time
2631 *0 *0 *0 0 1|0 0 2.1G 6.7G 1.1G 134 0 0|0 0|0 432k 158k 2 22:59:47
2579 *0 *0 *0 0 1|0 0 2.1G 6.7G 1.1G 133 0 0|0 0|0 425k 155k 2 22:59:48
2279 *0 *0 *0 0 1|0 0 2.1G 6.7G 1.1G 118 0 0|0 0|0 375k 138k 2 22:59:49
2628 *0 *0 *0 0 1|0 0 2.1G 6.7G 1.1G 138 0 0|0 0|0 433k 157k 2 22:59:50
> db.tests.stats()
{
"ns" : "test.tests",
"count" : 1250000,
"size" : 140000000,
"avgObjSize" : 112,
"numExtents" : 12,
"storageSize" : 174735360,
"lastExtentSize" : 50798592,
"paddingFactor" : 1,
@henricavalcante
henricavalcante / gist:21fcad506fa80b27450f
Created April 11, 2015 01:19
MONGODB - Indices em Background e Foreground
// Criação do índice em Foreground
> db.tests.createIndex({a:1});
// Criação em Background
> db.tests.createIndex({a:1}, {background:true});
$ mongotop 3
ns total read write 2015-04-10T18:00:42-03:00
test.tests 196ms 0ms 196ms
admin.system.roles 0ms 0ms 0ms
admin.system.version 0ms 0ms 0ms
@henricavalcante
henricavalcante / gist:312c02e2ed555f313685
Created April 10, 2015 20:39
MONGODB - Profiling - Consultas com mais de 500ms
db.system.profile.find({millis:{$gt:500}}).sort({ts:-1})
@henricavalcante
henricavalcante / gist:b4e3da0555cb1c791256
Last active August 29, 2015 14:18
MONGODB - Ativando o profile
$ mongod --profile 1 --slowms 2
> db.tests.explain().find({a:1});
{
"queryPlanner" : { // Informações do Explain
"plannerVersion" : 1,
"namespace" : "tests.tests",
"indexFilterSet" : false,
"parsedQuery" : {
"a" : {
"$eq" : 1
}
@henricavalcante
henricavalcante / gist:f3b3f628999c3d6ae1dc
Last active August 29, 2015 14:18
MONGODB - Criação de Indices
> db.tests.createIndex({a:1, b:1}); //A criação de indice pode ser simples ou composta
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
> db.tests.createIndex({a:-1}); //Ao passar o parametro negativo o índice é para ordem decrescente
{
"createdCollectionAutomatically" : false,