Skip to content

Instantly share code, notes, and snippets.

View daniel-roberts-10gen's full-sized avatar

Daniel daniel-roberts-10gen

View GitHub Profile
@daniel-roberts-10gen
daniel-roberts-10gen / Main.java
Created June 29, 2012 11:28
MongoDB Scratch pad
/**
* Example code for MongoDB CRUD
* and commands.
*
*/
package com.tengen.demo;
import com.mongodb.*;
import com.mongodb.util.*;
import com.mongodb.gridfs.*;
//Update if current
db.inventory.insert({sku:'abc',qty:10})
db.inventory.update({sku:'abc'},{$set : {qty:10}})
p = db.inventory.findOne()
db.inventory.update({sku:p.sku,qty:p.qty},{$inc : {qty : -1}})
db.getLastErrorObj()
db.inventory.update({sku:p.sku,qty:p.qty},{$inc : {qty : -1}})
use digg
//Map reduce functions
map = function() {
emit(this.user.name, {diggs: this.diggs, posts: 1});
}
reduce = function(key, values) {
var diggs = 0;
var posts = 0;
values.forEach(function(doc) {
db.adminCommand({setParameter:1, logLevel:5});
@daniel-roberts-10gen
daniel-roberts-10gen / queue.js
Created April 2, 2012 11:15
MongoDB Queuing Test
insertQ = function () {
for (i = 0; i < 1000; i++) {
db.queue.insert({message:"amessage", count:i, ts:new Date, status:"new"});
print("Count:" + i);
sleep(250);
}
}
dQueue = function() {
for(i=0;i<1000;i++) {
@daniel-roberts-10gen
daniel-roberts-10gen / Test.java
Created March 3, 2012 16:51
Test Hello World!
public class Test
{
public static void main(String args[])
{
System.out.println("Hello World!");
}
}
@daniel-roberts-10gen
daniel-roberts-10gen / shardsetuptest
Last active October 1, 2015 01:18
MongoDB Sharding Setup for localhost test
//Setup directories
mkdir r1
mkdir r2
mkdir r3
mkdir r4
mkdir r5
mkdir r6
mkdir config
//create replicasets