Jmeter-mongodb database additions and deletions change operation

Source: Internet
Author: User
Tags findone

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.