Nodejs-7. MongoDB Database

Source: Internet
Author: User
Tags robomongo

Mongodb

First, the concept:

1. Introduction: A database based on distributed file storage written by the C + + language

2. Function: Easy access to data

3. Download and install

3.1 Downloads
Bit:https://www.mongodb.com/download-center?jmp=nav#community
bit:https://www.mongodb.org/dl/win32/
3.2 Installation
Double-click the next step

4. MongoDB Graphical interface tool: Robomongo ==> Download official website https://robomongo.org/

4. Terminology Introduction

Database databases
Collection Collection
Document Documents ==> JSON
Field field ==> {name: ' Xiaohigh '}

Second, command-line operation

☆bin is generally used to store executable commands, such as '/usr/bin/usr/local/bin '

1. Create a folder c:/data/db
2. Start the database service
Command line to enter MONGODB command directory CD C:\Program Files\mongodb\server\3.6\bin
Run the Mongod command

Mongod
Mongod--dbpath C:/DATA/DB1
3. Connect to the database

Command line to enter MONGODB command directory CD C:\Program Files\mongodb\server\3.6\bin
Run the MONGO command
Mongo
MONGO 114.215.149.168
4. Execution of commands
4.1 Database
Switch database (no automatic creation) use dbname
Show all databases Show DBS
Displays the current database db
Deleting a database
Use dbname
Db.dropdatabase ();
4.2 Integrated
Create Collection db.createcollection (' users ');
View all Collections Show collections
Delete Collection Db.users.drop ()
Modify the name Db.users.renameCollection (' goods ');
4.3 documentation
Insert Document
Db.users.insert ({name: ' Xiaoming '})
Db.users.insertMany ([
{name: ' Xiaoa '},
{name: ' Xiaob '},
])
Gets all documents for the current collection Db.users.find ();
Delete Document Db.users.remove ({name: ' Xiaoa '});
Update document Db.users.update ({name: ' Xiaob '}, {$set: {age:30}});
Querying documents
Conditions
Equals Db.goods.find ({id:100})
Less than Db.goods.find ({ID: {$lt: 100}})
Greater than Db.goods.find ({ID: {$gt: 100}})
Less than or equal to Db.goods.find ({ID: {$lte: 100}})
Greater than or equal to Db.goods.find ({ID: {$gte: 100}})
Not equal to Db.goods.find ({id:{$ne: 100}});
Fuzzy query Db.goods.find ({title: {$regex:/stand-up/}}). Limit (5)
Logic and Db.goods.find ({title: {$regex:/dress/}, Price: {$lt: 100}});
Logical OR Db.goods.find ({$or: [{title:{$regex:/Spring/}}, {price:{$gt: 100}]});
Field Filter
Db.goods.find ({}, {title:1, _id:0}). Pretty ();
Intercept
Db.goods.find (). Limit (5)
Db.goods.find (). Skip (5). Limit (5)
Sort
Db.goods.find (). Sort ({id:-1})
Db.goods.find (). Sort ({id:1})
Formatted output
Db.goods.find (). Pretty ()

Nodejs-7. MongoDB Database

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.