This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Example code for MongoDB CRUD | |
* and commands. | |
* | |
*/ | |
package com.tengen.demo; | |
import com.mongodb.*; | |
import com.mongodb.util.*; | |
import com.mongodb.gridfs.*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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}}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.adminCommand({setParameter:1, logLevel:5}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Test | |
{ | |
public static void main(String args[]) | |
{ | |
System.out.println("Hello World!"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Setup directories | |
mkdir r1 | |
mkdir r2 | |
mkdir r3 | |
mkdir r4 | |
mkdir r5 | |
mkdir r6 | |
mkdir config | |
//create replicasets |