MongoDB Quick Start Notes (ii) the concept of MongoDB and simple operation _mongodb

Source: Internet
Author: User
Tags mongodb

MongoDB is a collection-oriented document database, unlike relational databases where tables, columns, rows, and MongoDB databases are composed of a series of documents. Here to introduce the concept of MongoDB and simple operation.

1, the following list of common relational database and MongoDB database simple conceptual differences:

2, MongoDB simple operation

(1) After starting the MongoDB database, use the command MONGO, as shown below, to connect to the test database by default.

MongoDB Shell version:3.2.6
Connecting To:test

Using the command show DBS, you can view all the databases and see only one local data, but the test database does not exist, and only when you build the collection and insert data into the collection will you actually build the table.

Common commands:

Show DBS shows all the databases

Switch the use database name to one of the data

Show collections displays all collections in the current database

Db. Collection name. Find () query all data under a collection in the current database

Db. Collection name. Insert ({"Key": "Value", "Key": "Value" ...}) to add data to a collection in the current database

Db. Collection name. Drop () Delete a collection

Db.dropdatabase () deletes the current database

Now let's use the above command to do a simple example: re-establish a data zyhtest and create a new collection student in Zyhtest and insert the data into the student.

> Use zyhtest
switched to db zyhtest
> Db.student.insert ({"Name": "Zhangsan", "Age":})
Writeresult ({"ninserted": 1})
> Show dbs
0.000GB
zyhtest 0.000GB
> Show Collections
student
> Db.student.find () c10/>{"_id": ObjectId ("5745b8a08dfa492b66e7d397"), "name": "Zhangsan", "Age":
> Db.student.drop ()
t Rue
> Show dbs local
0.000GB
> Db.student.insert ({"Name": "Zhangsan", "Age":)
Writeresult ({"ninserted": 1})
> show dbs local
0.000GB
zyhtest 0.000GB
> Show collections< C21/>student
> Db.dropdatabase ()
{"Dropped": "Zyhtest", "OK": 1}
> Show DBS

When inserting data, a primary key "_id" is automatically added

The above content is small to introduce the MongoDB Quick Start Note (ii) of the MONGODB concept and simple operation of the relevant knowledge, I hope to help you!

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.