Basic operations for mongodb addition, deletion, modification, and query

Source: Internet
Author: User
Tags findone mongodb query

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.

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.