Skip to content

Instantly share code, notes, and snippets.

View alexbevi's full-sized avatar
🙀

Alex Bevilacqua alexbevi

🙀
View GitHub Profile
@alexbevi
alexbevi / Execute-With-Retry.ps1
Created February 6, 2015 15:28
A PowerShell cmdlet that can be used to retry a failing ScriptBlock
<#
This function can be used to pass a ScriptBlock (closure) to be executed and returned.
The operation retried a few times on failure, and if the maximum threshold is surpassed, the operation fails completely.
Params:
Command - The ScriptBlock to be executed
RetryDelay - Number (in seconds) to wait between retries
(default: 5)
MaxRetries - Number of times to retry before accepting failure
@alexbevi
alexbevi / issue.md
Last active August 29, 2015 14:17
Mongoid + Unicorn on Azure

Ever since moving my application from an Ubuntu 14.04 server on EC2 to Azure, I get timeouts from my unicorn workers when running longer queries

I, [2015-03-17T13:51:06.280175 #33828]  INFO -- : worker=0 ready
E, [2015-03-17T13:51:17.924711 #33824] ERROR -- : worker=1 PID:33831 timeout (11s > 10s), killing
E, [2015-03-17T13:51:17.945216 #33824] ERROR -- : reaped #<Process::Status: pid 33831 SIGKILL (signal 9)> worker=1
I, [2015-03-17T13:51:17.947956 #33867]  INFO -- : worker=1 spawned pid=33867
I, [2015-03-17T13:51:17.948471 #33867]  INFO -- : Refreshing Gem list
I, [2015-03-17T13:51:24.800618 #33867]  INFO -- : worker=1 ready
curl https://gist.githubusercontent.com/alexbevi/3436040/raw/pre-commit.sh > .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
2016-01-29T21:06:05.180-0500 I CONTROL ***** SERVER RESTARTED *****
2016-01-29T21:06:05.241-0500 I CONTROL [initandlisten] MongoDB starting : pid=1745 port=27021 dbpath=/data 64-bit host=xxx
2016-01-29T21:06:05.241-0500 I CONTROL [initandlisten] db version v3.0.8
2016-01-29T21:06:05.241-0500 I CONTROL [initandlisten] git version: 83d8cc25e00e42856924d84e220fbe4a839e605d
2016-01-29T21:06:05.241-0500 I CONTROL [initandlisten] build info: Linux build3.ny.cbi.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2016-01-29T21:06:05.241-0500 I CONTROL [initandlisten] allocator: tcmalloc
...
2016-01-29T21:06:05.315-0500 W - [initandlisten] Detected unclean shutdown - /data/mongod.lock is not empty.
2016-01-29T21:06:05.315-0500 W STORAGE [initandlisten] Recovering data from the last clean checkpoint.
2016-01-29T21:06:05.324-0500 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=13G,session_max=20000,eviction=(threads_max=4),statistics=(fa
@alexbevi
alexbevi / ShowWiredTigerBackingFiles.js
Last active December 12, 2018 18:51
Scripts I've found useful while working with MongoDB
/***********
* Useful for finding out which xxxxxxx.wt files represent a collection in the dbpath
*
* output sample:
* admin.system.users - statistics:table:collection-14--2861149510510481026
* admin.system.version - statistics:table:collection-9--2861149510510481026
* local.me - statistics:table:collection-2--2861149510510481026
* local.oplog.rs - statistics:table:collection-4--2861149510510481026
* local.replset.election - statistics:table:collection-12--2861149510510481026
* local.replset.minvalid - statistics:table:collection-7--2861149510510481026
@alexbevi
alexbevi / 01 - README.md
Last active August 4, 2023 11:48
MongoDB World 2019 - The Sights (and Smells) of a Bad Query

The Sights (and Smells) of a Bad Query

This Gist contains links to the tools and templates used during my talk at MongoDB World 2019. If you have any questions about the content or feel I've missed something, please feel free to shoot me a note at [email protected] or leave a comment below.

Tools

MongoDB Atlas

MongoDB Atlas delivers the world’s leading database for modern applications as a fully automated cloud service engineered and run by the same team that builds the database. Proven operational and security practices are built in, automating time-consuming administration tasks such as infrastructure provisioning, database setup, ensuring availability, global distribution, backups, and more.

MongoDB Compass

@alexbevi
alexbevi / mongoid-dependencies.md
Last active January 26, 2020 03:04
Mongoid Dependency Details
Mongoid Version Date Ruby Version Mongo Ruby Driver Version AcitveModel Version ActiveSupport Version
v7.0.4 2019-06-12 17:53:59 -0400 ">= 2.2" ['>=2.5.1', '<3.0.0'] [">= 5.1", "<6.0.0"]
v7.0.3 2019-05-24 11:16:43 -0400 ">= 2.2" ['>=2.5.1', '<3.0.0'] [">= 5.1", "<6.0.0"]
v7.0.2 2018-09-17 16:18:41 -0400 ">= 2.2" ['>=2.5.1', '<3.0.0'] [">= 5.1", "<6.0.0"]
v7.0.1 2018-05-04 10:59:27 -0400 ">= 2.2" ['>=2.5.1', '<3.0.0'] [">= 5.1", "<6.0.0"]
v7.0.0 2018-03-12 14:17:28 +0100 ">= 2.2" ['>=2.5.1', '<3.0.0'] [">= 5.1", "<6.0.0"]
v7.0.0.beta 2017-07-21 11:18:33 +0200 ">= 2.2" ['>=2.4.1', '<3.0.0'] ["~> 5.1"]
v6.4.4 2019-05-24 15:16:51 -0400 ">= 2.2" ['>=2.5.1', '<3.0.0'] [">= 5.1", "<6.0.0"]
v6.4.3 2019-05-24 12:39:47 -0400 ">= 2.2" ['>=2.5.1', '<3.0.0'] [">= 5.1", "<6.0.0"]
@alexbevi
alexbevi / template.json
Last active May 31, 2021 19:28
Mgeneratejs template
{
"a": {
"$integer": {
"min": 1,
"max": 100
}
},
"b": {
"$integer": {
"min": 1,
require 'open-uri'
require 'nokogiri'
GITHUB_URL = "https://github.com/%s/network/dependents"
repos = [
{ name: "Ruby Driver", repo: "mongodb/mongo-ruby-driver" },
{ name: "Mongoid ODM", repo: "mongodb/mongoid" },
{ name: "C Driver", repo: "mongodb/mongo-c-driver" },
{ name: "C++ Driver", repo: "mongodb/mongo-cxx-driver" },
@alexbevi
alexbevi / README.md
Last active February 24, 2020 14:29
Variation of collStats command that can be run in a sharded environment through the Mongo shell and assemble the result in Javascript to bypass BSON size limitations

As a result of SERVER-44891 which was closed as Won't Fix I created this workaround. This script can be verified as follows using mtools, m and mgeneratejs:

First, initialize the cluster:

mkdir shardedCluster
m 4.0.9
mlaunch init --replicaset --nodes 1 --sharded 60 --csrs --binarypath $(m bin 4.0.9) --dir shardedCluster --auth