Skip to content

Instantly share code, notes, and snippets.

@joewagner
joewagner / Sharded mongodb environment on localhost
Last active May 7, 2024 13:33
Bash shell script that sets up a sharded mongodb cluster on a single machine. Handy for testing or development when a sharded deployment is required. Notice that this will remove everything in the data/config and data/shard directories. If you are using those for something else, you may want to edit this...
# clean everything up
echo "killing mongod and mongos"
killall mongod
killall mongos
echo "removing data files"
rm -rf data/config
rm -rf data/shard*
# For mac make sure rlimits are high enough to open all necessary connections
ulimit -n 2048
@joewagner
joewagner / gist:11326170
Created April 26, 2014 17:36
A class that runs a function on an interval. An instance of this class can be passed to many controllers, but only one interval will ever be set.
var RingOfPower = function (action, freq) {
if (typeof action === "undefined" || typeof freq === "undefined") {
throw new Error("must provide a function and an interval");
}
this.action = action;
this.frequency = freq;
};
RingOfPower.prototype.wield = function () {
clearInterval(this.interval);
@joewagner
joewagner / catchVersionErr.js
Last active December 22, 2015 11:48
Helper function to catch version errors when trying to update an Array field in a mongoose Model
// --- Dependancies ---
var _ = require('underscore');
var mongoose = require('mongoose');
// Any function that makes an update to a mongoose model that has an Array field can
// use this to catch version errors, and retry the update at most two times
var catchVersionErr = function () {
var updateFunc, callback, context, args = _.toArray(arguments);
context = args.shift();
@joewagner
joewagner / gist:5314301
Last active December 15, 2015 19:49
mongoose.js failing tests
You're not testing shards!
Please set the MONGOOSE_SHARD_TEST_URI env variable.
e.g: `mongodb://localhost:27017/database
Sharding must already be enabled on your database
․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․
․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․
You're not testing replica sets!
Please set the MONGOOSE_SET_TEST_URI env variable.