Skip to content

Instantly share code, notes, and snippets.

@scien
scien / .mongorc.js-example
Created February 1, 2013 04:42
.mongorc.js example
prompt = function() {
var ndocs, obj, p, sec;
ndocs = function(n) {
return "" + n + " document" + (n > 1 ? 's' : '');
};
db.setProfilingLevel(2);
obj = db.getLastErrorObj();
p = db.system.profile.find({
$and: [
{ns: {$not: /profile$/}},
@scien
scien / gist:6147369
Created August 3, 2013 18:00
M102 Week 3 Aggregation Framework 2 Data Entry
db.users.insert({"_id":"joe","joined":ISODate("2012-02-03T00:00:00Z"),"likes":["tennis","golf"]})
db.users.insert({"_id":"jane","joined":ISODate("2012-02-09T00:00:00Z"),"likes":["tennis","golf"]})
db.users.insert({"_id":"remesh","joined":ISODate("2012-05-05T00:00:00Z"),"likes":["basketball"]})
db.users.insert({"_id":"john","joined":ISODate("2012-03-05T00:00:00Z"),"likes":[]})
db.users.insert({"_id":"mary","joined":ISODate("2012-03-22T00:00:00Z"),"likes":["golf","sailing"]})
db.users.insert({"_id":"ann","joined":ISODate("2012-01-22T00:00:00Z"),"likes":["golf","basketball"]})
db.users.insert({"_id":"jim","joined":ISODate("2012-11-01T00:00:00Z"),"likes":["tennis","fishing","golf","snowboard","football"]})
@scien
scien / gist:6311114
Created August 22, 2013 18:41
Mongo Shell Database Help
> db.getSisterDB('week5').help()
DB methods:
db.addUser(username, password[, readOnly=false])
db.adminCommand(nameOrDocument) - switches to 'admin' db, and runs command [ just calls db.runCommand(...) ]
db.auth(username, password)
db.cloneDatabase(fromhost)
db.commandHelp(name) returns the help for the command
db.copyDatabase(fromdb, todb, fromhost)
db.createCollection(name, { size : ..., capped : ..., max : ... } )
db.currentOp() displays currently executing operations in the db
@scien
scien / gist:8263988
Created January 5, 2014 03:38
mongo --help
MongoDB shell version: 2.4.8
usage: mongo [options] [db address] [file names (ending in .js)]
db address can be:
foo foo database on local machine
192.169.0.5/foo foo database on 192.168.0.5 machine
192.169.0.5:9999/foo foo database on 192.168.0.5 machine on port 9999
options:
--shell run the shell after executing files
--nodb don't connect to mongod on startup - no
'db address' arg expected
@scien
scien / gist:8501640
Created January 19, 2014 07:29
run.sh from week 6 lesson 2 MongoDB for DBAs
#This from the MongoDB University Class M102:MongoDB for DBAs
#This is not an original script by me the author.
#Author Bill Glennon
#Date: January 18, 2014
# run processes for the cluster
# running on as single dev machine as a demo...
# make directories
> mongoimport --help
Import CSV, TSV or JSON data into MongoDB.
When importing JSON documents, each document must be a separate line of the input file.
Example:
mongoimport --host myhost --db my_cms --collection docs < mydocfile.json
options:
--help produce help message
initKeenIO: (project_id, write_key) ->
window.Keen = window.Keen || {
configure: (e) ->
this._cf = e
addEvent: (e,t,n,i) ->
this._eq = this._eq || []
this._eq.push [e,t,n,i]
setGlobalProperties: (e) ->
this._gp = e
onChartsReady: (e) ->
lass KeenHttpOutput < Fluent::Output
Fluent::Plugin.register_output('out-keen-http', self)
def initialize
super
require 'rubygems'
require 'eventmachine'
require 'em-http-request'
require 'cgi'
require 'json'
#!/bin/bash
# credit: Robert Larsen
function create_shard(){
shard=$1
repl_factor=$2
shard_name="shard_${shard}"
shard_dir=shard${shard}
init='rs.initiate({_id:"'${shard_name}'",members:['
@scien
scien / gist:cc38b2cba28bbbb30054
Last active December 2, 2016 16:05
iMessages Database
How to connect
> sqlite3 ~/Library/Messages/chat.db
Helpful Commands
sqlite> .help
sqlite> .tables
sqlite> .headers off
sqlite> .headers on
sqlite> .mode line
sqlite> .mode list