Skip to content

Instantly share code, notes, and snippets.

View christkv's full-sized avatar

Christian Amor Kvalheim christkv

View GitHub Profile
@christkv
christkv / replicaset_test_server.js
Created June 18, 2011 23:31
Server for replicaset test
var ReplicaSetManager = require('./test/tools/replica_set_manager').ReplicaSetManager;
var mongo = require('./lib/mongodb'),
Server = mongo.Server,
ReplSetServers = mongo.ReplSetServers,
http = require('http'),
debug = require('util').debug,
inspect = require('util').inspect;
var RS = new ReplicaSetManager({retries:120, arbiter_count:1, secondary_count:1, passive_count:0, name:'rs1'});
@christkv
christkv / gist:1056845
Created June 30, 2011 18:23
Output log
info it worked if it ends with ok
verbose cli [ 'node', '/usr/local/bin/npm', 'publish', 'mongodb' ]
info using npm@1.0.15
info using node@v0.4.9
verbose config file /Users/christian.kvalheim/.npmrc
verbose config file /usr/local/etc/npmrc
verbose publish [ 'mongodb' ]
info addNamed [ 'mongodb', '' ]
verbose addNamed [ null, '' ]
verbose GET mongodb
@christkv
christkv / node_knockout_mongo_2_article
Created August 24, 2011 21:39
A primer for GridFS using the Mongo DB driver
# A primer for GridFS using the Mongo DB driver
In the first tutorial we targeted general usage of the database. But Mongo DB is much more than this. One of the additional very useful features is to act as a file storage system. This is accomplish in Mongo by having a file collection and a chunks collection where each document in the chunks collection makes up a **Block** of the file. In this tutorial we will look at how to use the GridFS functionality and what functions are available.
## A simple example
Let's dive straight into a simple example on how to write a file to the grid using the simplified Grid class.
var mongo = require('mongodb'),
Server = mongo.Server,
Db = mongo.Db,
Grid = mongo.Grid;
@christkv
christkv / gist:3230153
Created August 1, 2012 19:57
A bit simpler
bc = {
auth:{
configuration_type: 'replicaset',
replicaset: {
db_name: 'auth',
servers: [
{host:'localhost',port:4000,options:{auto_reconnect:true}},
{host:'localhost',port:4001,options:{auto_reconnect:true}}
,{host:'localhost',port:4002,options:{auto_reconnect:true}}
],
//
// Ensures that mongod respects the batch write protocols
//
var collectionName = "batch_write_protocol";
var coll = db.getCollection(collectionName);
jsTest.log("Starting insert tests...");
coll.remove({});
var A = function() {
var _a = 1;
this.A = function() {
return _a;
}
}
var count = items.length;
for(var i = 0; i < items.length; i++) {
doSomething(function(err) {
count = count - 1;
if(count == 0) {
console.log("DONE")
}
var ReplSetManager = require('mongodb-tools').ReplSetManager
, ServerManager = require('mongodb-tools').ServerManager
, ShardingManager = require('mongodb-tools').ShardingManager
, mkdirp = require('mkdirp')
, path = require('path');
// Parse the passed in parameters
var yargs = require('yargs')
.usage('Start a local topology.\nUsage: $0')
.example('$0 -t replicaset', 'Run a local replicaset')
var cursor = GLOBAL.db.collection("data").find({ dataId : dataId }, { _id : 1, data : 2 }, { "sort" : [[ '_id', 1 ]] });
cursor.on('data', function(doc) {
});
cursor.on('error', function(err) {
});
cursor.on('end', function() {
});

Start Suite: legacy js parser

  • {'hello': 'world', n: 0} x 251,461 ops/sec ±2.07% (86 runs sampled)
  • {'hello': 'world', n: 0, doc: { a: 1}} x 112,596 ops/sec ±1.72% (85 runs sampled)
  • {'hello': 'world', n: 0, doc: { a: 1, b: { 'hello': 'again' }}} x 69,673 ops/sec ±3.34% (86 runs sampled)

Start Suite: legacy c++ parser

  • {'hello': 'world', n: 0} x 645,325 ops/sec ±0.92% (97 runs sampled)
  • {'hello': 'world', n: 0, doc: { a: 1}} x 350,544 ops/sec ±1.40% (95 runs sampled)