Basic operations commonly used by mongoVUE on mongodb

Basic operations commonly used by mongoVUE on mongodb

1.     Connect to the mongodb server :

1. Double-click mongoVUE to enter the interface as shown below:


2. Click the "+" in the above figure, the following figure will appear, enter the ip, port, username, password of the mongodb server to be connected, and the database to be connected, etc.:


3. After filling in the information, click "test". If successful, the following interface will pop up, and then click "save"; User authentication, you do not need to enter a username and password):


4. After Save, the following interface will appear. When you open it next time, if you want to connect to this mongodb, you don’t need to repeat the first two steps. Click “connection” to connect to the mongodb server:


5. The following figure is the mongoVUE interface that can be operated after the connection is successful. You can open it on the left to see the related db and collection:


2.     Insert data:

1. As shown in the figure above, there are collections such as alarm and mongoTest. For example, to insert a piece of data into the mongoTest collection, first right-click on mongoTest, and select "insert/import Documents..." in the following pop-up box:


2. Fill in the document to be inserted in the following pop-up box. The document is in json format, such as "{"name":"aaa","age":1}", and then click "insert" to insert a piece of data into In the mongoTest collection, as shown in the figure:


3.     Query data:

1. First insert multiple pieces of data into mongoTest. For example, to query the data in this collection, right-click on mongoTest and select "find":


2. After Find, the following interface will appear on the right side. If you want to query all data in mongoTest, you can enter "{}" in the input box after "{find}", or enter nothing, and then click the arrow Click the "find" button in the upper right corner, and all data will be queried; pay attention to the place pointed by the arrow in the lower right corner, which represents the number of queries, 50 by default, which can be modified as needed.


3. In the following interface that appears, click the "table view" pointed by the arrow, and the data will be displayed in the form of a table, as shown in the figure:


4. Conditional query 1: For example, to query the data whose name is aaa, you can enter the condition "{"name": "aaa"}" in the input box after "{find}", which is still in json format, and click on the upper right corner. After the find button, you will see that the data is queried below, as shown in the figure:


5. Conditional query 2: Similarly, if there are multiple conditions, you can add the corresponding key:value to "{"name":"aaa"}". For example, to query the data whose name is aaa and age is 111 ; But it should be noted that the type of the corresponding value must match. If the value in the database is not a string, the value cannot be quoted, otherwise the condition does not match, and it cannot be found:


6. Conditional query 3: Use operators $gt, $lt, etc. to query data ($gt, $gte, $lt, $lte are >, >=, <, <=), for example, to query age between 2 and 5 You can enter "{"age": {"$gte": 2, "$lt": 5}}" in the input box after "{find}", and you can query all age in Data between 2 and 5:


7. Conditional query 4: To limit the number of queries, you only need to change the value of limit. For example, there are multiple pieces of data with the name ccc in mongoTest, but the age is different, they are 3, 4, 5, and 6, respectively. If you only need Two days before the query, you can change the limit to 2:


8. Conditional query 5: Sort the query results, as shown in Figure 1 below, you can see that when no conditions are added, the query data age is disordered:


If you want the queried data to be sorted in the positive order of age, you can enter the sorting condition "{"age":1}" in the input box after "{sort}"; if you want to sort in reverse order of age, you can enter "{"age":-1}":


9. Conditional query 6: Conditional query and sorting. For example, to query the data whose name is ccc, and the age is between 2 and 5, and arrange it in the reverse order of age, you can enter it as shown below:


Fourth,     delete data:

1. Right-click on mongoTest and select "remove":


2. Enter the deletion conditions in the following pop-up box. For example, to delete the data whose name is aaa, enter "{"name":"aaa"}", and then click the remove arrow pointed to in the lower left corner:


3. After that, the following pop-up box will appear, showing how many documents are matched according to the conditions. Click remove to delete all documents (records) that match the conditions entered in the previous step:


Fifth,     modify the data:

1. Right-click on mongoTest and select "update":


2. After Update, the following interface will appear. Enter the query conditions on the left to match the document to be modified. For example, to modify the document whose name is bbb, you can enter "{"name": "bbb" as shown in the figure. }"; In the input box on the right, enter the document that needs to appear after the change, enter "{"age":5}" in the figure, then after modification, all documents whose name is bbb will be replaced with "{"age": 5}", update1 will only modify the first matching document, and updateall will modify all matching documents:


Before modification, you can see that a document with the name bbb exists:


After the modification, you can see that there is no document with the name bbb, but a new document with only age 5:


3. The modification in the above step is to cover the entire document. If you want to modify a field, you must use the $set operator; for example, to change the age in the data whose name is eee to 100, you can Enter "{"$set":{"age":100}}" in the input box on the right:


Query again, you can see that the data whose name is eee has become: {"name":"eee","name":100}:


Reprinted from: https://blog.csdn.net/tuzongxun/article/details/50345161

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326798802&siteId=291194637