Some enterprises are using non-relational databases such as mongodb in Kunming. Therefore, they must have basic knowledge of non-relational databases in any case, this time I sorted out some of the most basic operations for adding, deleting, modifying, and querying mongodb.
1. Insert data
A simple table structure may be a single column of json. However, if the situation is complicated, nesting may occur. This is the simplest case.
The insert command is relatively simple. You can directly use db. Table name. insert (json string) as follows:
2. delete data
The command is also simple: db. Table name. remove (json condition)
3. Simple Query
The command is also very simple. If you replace the keyword with "find", the query result of "find" may be multiple or single. If there is only one query result, you can also use "findOne ".
The usage of findone is as follows:
Both find and findOne can be followed by conditions.
4. modify data
It is very dangerous to directly use the update method in mongodb. If the number of columns to be updated is smaller than the total number of columns, other columns not updated will become null after update.
The first json after update is the condition, followed by the json consisting of the fields and values to be updated
It's easy, but the mongodb query is far more than this, and we will introduce some other addition, deletion, modification, and query methods later.