MongoDB Learning (ii) Visual interface

Source: Internet
Author: User

First, the installation of Visual Interface 1, Mongobooster installation and configuration 1, download and install

: Https://nosqlbooster.com/downloads

After the download is complete, click Install directly:

Installation Complete Popup interface:

2. Click Create Link:

3. Click the test Connection Link:

4. Click Save & Connect link to the local database after testing OK:

2, write the operation statement in the Mongobooster

1. View Collections

2. Add a new piece of data

3. Modify a piece of data

4. View Documents

Ii. simple application in Java 1. Preparing the driver package

2. Get the names of all databases
1  Packagecom.mongodb.study.test;2 3 ImportCom.mongodb.Mongo;4 Importorg.junit.Test;5 6 Importjava.util.List;7 8 /**9  * @authorzt1994 2018/3/9 10:55Ten  */ One  Public classTestmongodb { A  -     /** - * Get names of all databases the      */ - @Test -      Public voidTestgetalldbname () { -         //1. Create a Mongo object +Mongo Mongo =NewMongo ("localhost", 27017); -List<string> Databasenames =mongo.getdatabasenames (); +          for(String databasename:databasenames) { ASystem.out.println ("DatabaseName:" +databaseName); at         } -     } -}

Console output:

3. Get all the collections under the specified database
1     /**2 * Gets all the collections under the specified database3      */4 @Test5      Public voidtestgetcollections () {6         //1. Create a Mongo object7Mongo Mongo =NewMongo ("localhost", 27017);8         //2. Link to the specified database9DB db = Mongo.getdb ("zt01");TenSet<string> Collectionnames =db.getcollectionnames (); One          for(String collectionname:collectionnames) { ASystem.out.println ("CollectionName:" +collectionname); -         } -}

Console output:

4. Gets the specified collection under the specified database and obtains the data
1     /**2 * Gets the specified collection under the specified database and gets the data3      */4 @Test5      Public voidtestgetonecollection () {6         //1. Create a Mongo object7Mongo Mongo =NewMongo ("localhost", 27017);8         //2. Link to the specified database9DB db = Mongo.getdb ("zt01");TenDbcollection collection = Db.getcollection ("zt01"); One         //Get Data ADbcursor dbobjects =Collection.find (); -          for(DBObject dbobject:dbobjects) { -System.out.println ("DBObject:" +dbobject.tostring ()); the         } -}

Console output:

5, add data 1, create a tool library, connect to the specified database collection
1  PackageCom.mongodb.study.util;2 3 ImportCom.mongodb.DB;4 Importcom.mongodb.DBCollection;5 ImportCom.mongodb.Mongo;6 7 /**8  * @authorzt1994 2018/3/9 11:00am9  */Ten  Public classMongodbutil { One  A     /** - * Create a link to the specified database collection -      * @return the      */ -      Public Staticdbcollection createcollection () { -         //1. Create a Mongo object -Mongo Mongo =NewMongo ("localhost", 27017); +         //2. Link to the specified database -DB db = Mongo.getdb ("zt01"); +         //3. Create a collection ADbcollection collection = Db.getcollection ("zt01"); at         returncollection; -     } -}
2. Test increase data
1     /**2 * Test Add Data3      */4 @Test5      Public voidTestadd () {6Dbcollection collection =mongodbutil.createcollection ();7         //1. Data Objects8Basicdbobject Basicdbobject =NewBasicdbobject ();9         //2. Add DataTenBasicdbobject.append ("id", "01"); OneBasicdbobject.append ("Name", "New data"); A         //3. Inserting into the collection - Collection.insert (basicdbobject); -         //4. View Collections theDbcursor dbobjects =Collection.find (); -          for(DBObject dbobject:dbobjects) { -System.out.println ("DBObject:" +dbobject.tostring ()); -         } +}

Console output:

6. Delete data
1     /**2 * Delete Data3      */4 @Test5      Public voidTestdelete () {6Dbcollection collection =mongodbutil.createcollection ();7         //1. Data Objects8Basicdbobject Basicdbobject =NewBasicdbobject ();9         //2. Specify the data to deleteTenBasicdbobject.append ("id", "01"); One         //3. Delete Data A Collection.remove (basicdbobject); -         //4. View Collections -Dbcursor dbobjects =Collection.find (); the          for(DBObject dbobject:dbobjects) { -System.out.println ("DBObject:" +dbobject.tostring ()); -         } -}

Console output:

You can see that the "id": "01" of the data has been deleted.

7. Update the modified data
1     /**2 * Update Data3      */4 @Test5      Public voidtestupdate () {6Dbcollection collection =mongodbutil.createcollection ();7         //1. Data Objects8Basicdbobject Basicdbobject =NewBasicdbobject ();9         //2. Specify the data you want to modifyTenBasicdbobject.append ("name", "Mike"); One         //3. Specify the data to be modified ABasicdbobject updateobj =NewBasicdbobject (); -Updateobj.append ("Nameupdate", "Test Modify name"); -         //4. Updating Data the collection.update (Basicdbobject, updateobj); -         //5. View Collections -Dbcursor dbobjects =Collection.find (); -          for(DBObject dbobject:dbobjects) { +System.out.println ("DBObject:" +dbobject.tostring ()); -         } +}

Console output:

You can see that the data has been modified.

8. View specified data
1     /**2 * Query specified data3      */4 @Test5      Public voidTestquery () {6Dbcollection collection =mongodbutil.createcollection ();7         //1. Data Objects8Basicdbobject Basicdbobject =NewBasicdbobject ();9         //2. Specify the fields that the data you want to query containsTenBasicdbobject.append ("title", "MongoDB"); One         //3. Querying Data ADbcursor dbobjects =Collection.find (basicdbobject); -          for(DBObject dbobject:dbobjects) { -System.out.println ("DBObject:" +dbobject.tostring ()); the         } -}

Console output:

MongoDB Learning (ii) Visual interface

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.