Skip to content

Instantly share code, notes, and snippets.

View cristopher-rodrigues's full-sized avatar
🏠
Working from home

Cristopher Rodrigues cristopher-rodrigues

🏠
Working from home
View GitHub Profile
@cristopher-rodrigues
cristopher-rodrigues / rename.js
Created March 10, 2016 12:43
mongo rename db
db.copyDatabase("oldDb","newDb","connection")
use oldDb
db.dropDatabase();
@cristopher-rodrigues
cristopher-rodrigues / set.js
Created March 10, 2016 12:42
topology destroyed (mongo+node+mongolab)
var options = {
server: { socketOptions: { keepAlive: 1, connectTimeoutMS: 30000 } },
replset: { socketOptions: { keepAlive: 1, connectTimeoutMS: 30000 } }
};
mongoose.connect(secrets.db, null, options);
@cristopher-rodrigues
cristopher-rodrigues / gist:d672e3cb276334906acb
Last active February 7, 2017 02:16
ssl example using node
openssl genrsa -out server-key.pem 2048
openssl req -new -key server-key.pem -out server-csr.pem
OR
openssl req -new -newkey rsa:2048 -nodes -keyout server.key -out server.csr
and
openssl x509 -req -in server-csr.pem -signkey server-key.pem -out server-cert.pem
past in ssl provider: cat server-csr.pem
@cristopher-rodrigues
cristopher-rodrigues / indexes.js
Last active February 7, 2017 02:17
list all indexes on database (mongo)
db.getCollectionNames().forEach(function(collection) {
indexes = db[collection].getIndexes();
print("Indexes for " + collection + ":");
printjson(indexes);
});
@cristopher-rodrigues
cristopher-rodrigues / mongobigagg.js
Created January 17, 2016 01:07
mongo + mongoose big aggregate $group
agregação var = MyModel.aggregate (...);
aggregation.options = {allowDiskUse: true};
aggregation.exec (function () {});
@cristopher-rodrigues
cristopher-rodrigues / upstart.markdown
Last active February 7, 2017 02:17
NodeJS upstart forever service linux
Save file /etc/init/yourapp.conf
#!upstart
description "Upstart script for yourapp Server"

start on startup
stop on shutdown

expect fork
@cristopher-rodrigues
cristopher-rodrigues / lc.bash
Created December 18, 2015 11:15
mongo locale config
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale-gen en_US.UTF-8
dpkg-reconfigure locales
@cristopher-rodrigues
cristopher-rodrigues / mongself.js
Last active December 17, 2015 14:33
mongo save usign self value
db.collection.find({}).snapshot().forEach( function (obj) {
obj.prop1 = obj.prop2;
db.collection.save(obj);
});
db.collection.find({}).snapshot().forEach( function (obj) {
obj.prop1 = parseInt(obj.prop1);
db.collection.save(obj);
});
@cristopher-rodrigues
cristopher-rodrigues / magg.js
Last active December 16, 2015 23:39
mongo aggregate
db.collection
.aggregate(
[
{$match:{$text:{$search: "STRING"}, {/*wEVER*/}}},
{$lookup:{from: 'otherCollectionJoin', localField: 'p', foreignField: '_id', as: 'otherCollectionJoin'}},
{$unwind:"otherCollectionJoin"},
{
$group:{
"_id":"$_id"
, type: {$addToSet: "otherField"}
@cristopher-rodrigues
cristopher-rodrigues / mopen.markdown
Created December 11, 2015 20:27
mongo open host

check UFW status

ufw status

OPEN 22

ufw allow 22

UFW ENABLE