Basic operations for databases and collections

Source: Internet
Author: User
Tags sqlite database

MongoDB is a product between a relational database and a Philippine relational database. It supports very loose data structures and is a JSON-like Bson format.

MongoDB is a collection-oriented store. In MongoDB, a database contains multiple collections, and one collection contains multiple documents.

$ sudo service MongoDB start #linux下启动mongodb

$ MONGO #进入MongoDB命令行操作界面

A mongodb can create multiple databases, use show DBS to view a list of all databases, and execute a DB command to view the current database object or collection. The run use command can be linked to the specified database.

> Use test #连接到test数据库 database name can be any character, but cannot have spaces, dot good and $ characters.

The document is the core of MongoDB. Similar to each row of data in the SQLite database. Multiple keys and their associated values together are documents. Storing data in MongoDB using a class JSON Bson, Bson data can be understood to add some data types that are not in JSON based on JSON.

There are two kinds of logical relationships in a document, one is an embedded relationship and the other is a reference relationship.

A collection is a combination of a set of documents that can store different document structures in MONGOBD.

Data cacou information is stored in the collection, and they use a unified system naming: dbname.system.*

Db.system.namespaces List all namespaces

Db.system.indexs List all indexes

Db.system.profile Listing Database profile information

Db.system.users List of users accessing the database

Db.system.sources Listing Server information

> Use MyDB #创建数据库

> DB #查看当前连接的数据库

> Show DBS #查看当前链接的数据库 mongdb not show empty database

> db.dropdatabase () #销毁数据库

> Use MyDB #创建数据库mydb

> Db.createcollection ("Users") #在mydb下创建集合users

> Show Collections #查看当前创建的集合

> Db.users.drop () #删除user集合

> Db.users.insert ([{name: "Jack", email: "[email protected]"},{name: "Jim", Email: "[email protected]"}])

> Db.users.save ([{name: "Hello", email: "[email protected]"},{name: "World", Email: "[email protected]"}])

The difference between the save and insert of MongoDB.

1. Using the Save and insert functions, the Wakahara object does not exist, they can all want to collection insert the data, if already exist, save will call the update update inside the record, and insert will ignore the operation

2.insert can be inserted in a single list at a time, without traversing, high efficiency. Save needs to traverse the list and insert it.

 

Basic operations for databases and collections

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.