In the daily testing process will be found that some of the test data are obtained through the database, commonly used data such as SQL, Oracle, such database jmeter have dedicated plug-in to use JDBC, today to tell you about MongoDB this database JMeter daily operations.
In the 3.1 version of the time, JMeter also has the instance of MongoDB, to the 3.2 version of the instance also did not, then we have to how to operate, small part of the use of BeanShell here instead of plug-ins, because of the small code is insufficient, unable to write plug-ins to facilitate everyone.
ImportCom.mongodb.BasicDBObject;ImportCom.mongodb.DB;Importcom.mongodb.DBCollection;ImportCom.mongodb.DBCursor;ImportCom.mongodb.DBObject;ImportCom.mongodb.Mongo;Try{Mongo Connection=NewMongo ("${mongo}"); ---database IP address DB db= Connection.getdb ("${db}"); ---database name dbcollection users=db.getcollection ("${user}"); ---set noun dbcollection users1=db.getcollection ("${user1}"); ---set noun 1 dbobject user=NewBasicdbobject (); User.put ("Mobile", "${name}"); ---match condition DBObject user1=NewBasicdbobject (); User1.put ("Mobile", "${name}"); ---Match Criteria//Collection.findone (user1)//Query Single//Remove Delete Files//Insert Inserts a file//Update Updatesusers.remove (user); Users1.remove (user1); Dbcursor DbUser=users.find (user); Dbcursor DbUser1=Users1.find (user1); //Match All while(Dbuser.hasnext ()) {System.out.println ("~~~~~~~~"+Dbuser.next ()); } //Match All while(Dbuser1.hasnext ()) {System.out.println ("~~~~~~~~"+Dbuser1.next ()); } } Catch(Exception e) {e.printstacktrace (); }
Note that the above code, the small part of the write is find () means to query all parameters that meet the criteria, if you only query one piece of data, use FindOne ()
Jmeter-mongodb database additions and deletions change operation