Skip to content

Instantly share code, notes, and snippets.

@banker
banker / test.rb
Created August 5, 2011 15:02
Test Ruby / Mongoid
require 'rubygems'
require 'mongoid'
require 'test/unit'
if BSON::BSON_CODER != BSON::BSON_C
raise "Please ensure that bson_ext is installed and loaded."
end
class LionTest < Test::Unit::TestCase
DB = "test-mongoid-lion"
@banker
banker / load.js
Created May 3, 2011 14:58
load.js
var str = "";
for(i=0; i<10000; i++) {
str += "0";
}
for(n=0; n<100; n++) {
for(i=0; i<10000; i++) {
db.foo.save({n: "user " + i, data: str});
}
}
@banker
banker / test_mongoid.rb
Created April 14, 2011 21:44
Simple Mongoid Benchmark
require 'rubygems'
require 'mongoid'
Mongoid.configure do |config|
config.master = Mongo::Connection.new['foo']
end
class Item
include Mongoid::Document
/*
* Title: tutorial.c
* Author: Christopher Triolo
* Build & Run:
* $ gcc -Isrc --std=c99 tutorial.c /path/to/mongo-c-driver/src/*.c -I /path/to/mongo-c-driver/src/ -o tutorial
* $ ./tutorial
* connection succeeded
* ...
* connection closed
*/
#include "test.h"
#include "bson.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(){
bson_buffer bb;
bson b, sub;
bson_iterator it;
@banker
banker / fork_fail.rb
Created March 17, 2011 17:32
Forking without resetting the Connection.
require 'rubygems'
require 'mongo'
# A class to store our DB object
class Foo
def self.db
@@db ||= Mongo::Connection.new['stuff']
end
end
require 'mongo'
c = Mongo::Connection.new
c['test']['nums'].remove
c['test']['nums'].save({:n => 2147483635})
1000.times do
c['test']['nums'].update({}, {"$inc" => {:n => 1}})
p c['test']['nums'].find_one
@banker
banker / basics.rb
Created January 26, 2011 19:42
Files used in a presentation on MongoDB and Ruby
require 'rubygems'
require 'mongo'
@con = Mongo::Connection.new
# Instance of Mongo::DB
@db = @con['webinar']
# Instance of Mongo::Collection
@col = @db['users']
@banker
banker / sample-mongodb.php
Created January 25, 2011 22:14
Sample PHP program using MongoDB and the official PHP driver.
<?php
// connect
$m = new Mongo();
// select a database
$db = $m->training;
$coll = $db->messages;
@banker
banker / sample-mongodb.java
Created January 25, 2011 21:52
A sample program for MongoDB written in Java using the official Java driver.
import com.mongodb.Mongo;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.mongodb.DBCursor;
import com.mongodb.WriteConcern;
public class Test {