Skip to content

Instantly share code, notes, and snippets.

hadoop jar mongo-hadoop-streaming-assembly*.jar -mapper mapper.rb -reducer reducer.rb -inputURI mongodb://127.0.0.1/twitter.in -outputURI mongodb://127.0.0.1/twitter.out
@TylerBrock
TylerBrock / aggregate.js
Created June 25, 2012 17:53 — forked from cwestin/aggregate.js
Mongo shell script and sample documents used for my aggregation talk at MongoSF
/* sample aggregate command queries */
// make sure we're using the right db; this is the same as "use mydb;" in shell
db = db.getSisterDB("aggdb");
// just passing through fields
var p1 = db.runCommand(
{ aggregate : "article", pipeline : [
{ $project : {
tags : 1,
pageViews : 1
@TylerBrock
TylerBrock / aggregation.js
Created June 25, 2012 18:18 — forked from cwestin/aggregation.js
Mongo shell script and sample documents used for my aggregation talks 12/2011
// make sure we're using the right db; this is the same as "use aggdb;" in shell
db = db.getSiblingDB("aggdb");
// simple projection
var p1 = db.runCommand(
{ aggregate : "article", pipeline : [
{ $project : {
tags : 1,
pageViews : 1
}}
db.getSiblingDB("admin");
var databases = null;
databases = db.runCommand("listDatabases");
if(databases){
for(var i=0;i<databases.databases.length;i++){
//TODO skip if it's the admin database
@TylerBrock
TylerBrock / latency.txt
Created July 2, 2012 19:54 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD* 150,000 ns 0.15 ms
db.getSiblingDB("admin");
var databases = null;
databases = db.runCommand("listDatabases");
if(databases){
for(var i=0;i<databases.databases.length;i++){
//TODO skip if it's the admin database
#!/usr/bin/env mongo --quiet
var m = new Mongo();
var db = m.getDB('test');
var t = db.getCollection('whatever');
t.find( { group:3, 'x.a':1 }, { 'x.$':0 } );
printjson(db.getLastErrorCmd());
assert.eq( 16345, db.getLastErrorCmd().code, "exclusion of positional operator" );
@TylerBrock
TylerBrock / log
Created July 4, 2012 17:29
MongoDB v2.1.2 fsyncUnlock()
Wed Jul 4 13:23:37 [conn1587] end connection 127.0.0.1:50894 (5 connections now open)
Wed Jul 4 13:23:37 [conn1581] end connection 127.0.0.1:50888 (4 connections now open)
Wed Jul 4 13:23:37 [conn1589] end connection 127.0.0.1:50896 (3 connections now open)
Wed Jul 4 13:23:37 [conn1591] end connection 127.0.0.1:50898 (2 connections now open)
Wed Jul 4 13:23:42 [conn59] CMD fsync: sync:1 lock:1
Wed Jul 4 13:23:43 [fsyncLockWorker] removeJournalFiles
Wed Jul 4 13:23:43 [conn59] db is now locked for snapshotting, no writes allowed. db.fsyncUnlock() to unlock
Wed Jul 4 13:23:43 [conn59] For more info see http://www.mongodb.org/display/DOCS/fsync+Command
Wed Jul 4 13:23:43 [conn59] command admin.$cmd command: { fsync: 1.0, lock: true } ntoreturn:1 keyUpdates:0 locks(micros) W:10958 r:1268 reslen:168 699ms
Wed Jul 4 13:23:44 [conn59] CMD fsync: sync:1 lock:1
require 'mongo'
require './model/mongoModule'
require './model/user'
if ENV['RACK_ENV'] == 'production'
CONNECTION = Mongo::Connection.from_uri(ENV['MONGOHQ_URL'])
else
CONNECTION = Mongo::Connection.new("localhost", 27017)
end
DB = CONNECTION.db('milieu')
class Monitor
def initalize
puts "whatup"
@thread = Thread.new {
loop do
puts "ReplSetMonitor refreshing!"
sleep(1)
end
}
end