This file contains hidden or 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
| 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; |
This file contains hidden or 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
| 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. |
This file contains hidden or 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
| 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"}); |
This file contains hidden or 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.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"}); |
This file contains hidden or 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
| > 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; | |
| ... } | |
| ... } |
This file contains hidden or 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
| > 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; |
This file contains hidden or 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
| > 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; | |
| ... } | |
| ... } |
This file contains hidden or 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
| > 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); |
This file contains hidden or 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
| SELECT DATE(date), count(*) | |
| FROM collection | |
| WHERE stuffDate > from AND stuffDate < to | |
| GROUP BY DATE(date); |
This file contains hidden or 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
| 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});" + | |
| "}" + | |
| "});" + |