Skip to content

Instantly share code, notes, and snippets.

import java.util.ArrayList;
import org.apache.jmeter.samplers.AbstractSampler;
import org.apache.jmeter.samplers.Entry;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.testbeans.TestBean;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;
import com.mongodb.DB;
displayName=MongoDB Script Sampler
sampler.displayName=Script
script.displayName=The script to run
script.shortDescription=Add your mongo shell script as you would via the mongo shell.
import java.beans.PropertyDescriptor;
import org.apache.jmeter.testbeans.BeanInfoSupport;
import org.apache.jmeter.testbeans.gui.TextAreaEditor;
public class SamplerBeanInfo extends BeanInfoSupport {
public SamplerBeanInfo() {
super(Sampler.class);
createPropertyGroup("sampler", new String[]{"script"});
@JanPaulEttles
JanPaulEttles / jandefence
Created March 28, 2012 15:16
jandefence
>db.coll.insert({"someNumber": "1", "someOtherRubbish": "blah"});
>db.coll.insert({"someNumber": "10", "someOtherRubbish": "meh"});
>db.coll.insert({"someNumber": "20", "someOtherRubbish": "feh"});
>db.coll.insert({"someNumber": "50", "someOtherRubbish": "eh"});
>db.coll.insert({"someNumber": "90", "someOtherRubbish": "blahblah"});
>db.coll.insert({"someNumber": "100", "someOtherRubbish": "fehblah"});
>db.coll.insert({"someNumber": "110", "someOtherRubbish": "mehblah"});
>db.coll.insert({"someNumber": "120", "someOtherRubbish": "blaheh"});
>db.coll.insert({"someNumber": "150", "someOtherRubbish": "ehblah"});
>db.coll.insert({"someNumber": "200", "someOtherRubbish": "fehfehblah"});
@JanPaulEttles
JanPaulEttles / jandefence4
Created March 28, 2012 15:14
jandefence4
> var cursor = db.coll.find().sort({"someNumber":1});
> var max = -1;
> while(cursor.hasNext()) {
... var current = parseInt(cursor.next().someNumber);
... print(max + ' ' + current);
... if(current > max) {
... print(max + ' ' + current);
... max = current;
... }
... }
@JanPaulEttles
JanPaulEttles / jandefence3
Created March 28, 2012 15:13
jandefence3
> var cursor = db.coll.find().sort({"someNumber":1});
> var max = -1;
> var count = 0;
> while(cursor.hasNext()) {
... count++;
... var current = cursor.next();
... print(max + ' ' + current.someNumber);
... if(current.someNumber> max) {
... print(max + ' ' + current.someNumber);
... max = current.someNumber;
@JanPaulEttles
JanPaulEttles / jandefence2
Created March 28, 2012 15:12
jandefence2
> var cursor = db.coll.find().sort({"someNumber":1});
> var max = -1;
> var count = 0;
> while(cursor.hasNext()) {
... count++;
... var current = cursor.next();
... if(current.someNumber > max) {
... max = current.someNumber;
... }
... }
@JanPaulEttles
JanPaulEttles / jandefence1
Created March 28, 2012 15:11
jandefence1
> var cursor = db.coll.find().sort({"someNumber":1});
> var max = -1;
> while(cursor.hasNext()) {
... var current = cursor.next();
... if(current.someNumber > max) {
... max = current.someNumber;
... }
... }
90
> print(max);
SELECT DATE(date), count(*)
FROM collection
WHERE stuffDate > from AND stuffDate < to
GROUP BY DATE(date);
DBCollection coll = db.getCollection("collection");
String map = "function() {" +
"if(this.arrayOfStuff) {" +
"this.arrayOfStuff.forEach(function(stuff) {" +
"if(stuff.date > from && stuff.date < to) {" +
"var date = Date.UTC(stuff.date.getFullYear(), stuff.date.getMonth(), stuff.date.getDate(), stuff.date.getHours());" +
"emit({day: date}, {count:1});" +
"}" +
"});" +