Ubuntu System Installation MongoDB

Source: Internet
Author: User
Tags install mongodb

Installing MongoDB

sudo apt-get install MongoDB

... ...

Setting up client connections

Open File/etc/mongodb.conf Note permissions

Modify bind_ip=127.0.0.1 to bind_ip=0.0.0.0

Setting the connection user name and password and common commands

Enter MongoDB Interactive mode

>mongo

Create a connected user

>use Admin

>db.adduser (' username ', ' password ')

User authentication

>db.auth (' username ', ' password ')

View data sets

>db.collections

... ...

View the list of users

>db.system.users.find ()

View All Users

>show User

Delete User

>db.removeuser (' username ')

View all databases

>show DBS

View Data Set Status

>db.printcollectionstats ()

View Database Introduction

>show profile

Delete a data set

>db.demo_col.drop ()

Delete current Database

>db.dropdatabase ()

Service startup and shutdown

sudo service MongoDB start

sudo service MongoDB stop

Delete and change [ database name Demodb]

Add data

>db.demodb.save ({' name ': ' Bob ', ' email ': [' [email protected] ', ' [email protected] '], ' sex ': 1})

modifying data

Format: Db.collection.update (criteria, objnew, Upsert, Multi)

Criteria:update query conditions, similar to those in the SQL update query
Objnew:update objects and some updated operators (such as $, $inc ... ) can also be understood as the SQL update query within the set after the
Upsert: This parameter means that if there is no record of update, insert Objnew,true is inserted, default is False, not inserted.
Multi:mongodb default is False, only update the first record found, if this parameter is true, the condition is checked out all the records are updated.

>db.demodb.update ({' name ': ' Bob '},{' $set ': {' sex ': 0},upsert=true,multi=true})

Delete data

>db.demodb.remove ({' name ': ' Bob '})

Delete all records

>db.demodb.remove ()

Querying all data

>db.demodb.find ()

Query the topmost piece of data

>db.demodb.findone ()

Query the data for a specified number of bars based on criteria

>db.demodb.find ({' Sex ': 0}). Limit (2)

Skips a specified number of bars

>db.demodb.skip (10)

Sorting sort

>db.demodb.find ({' Sex ': 0}). Sort ({' name ':-1})

Count operations

>db.demodb.find ({' Sex ': 0}). Count ()

>db.demodb.count ()

Querying for specified columns, removing duplicates

>db.demodb.distinct (' sex ')

Sub-Object Lookup

>db.demodb.distinct ({' addr.province ': ' Beijing '})

Conditional operator Lookup

GT: Greater Than

LT: less than

GTE: greater than or equal to

LTE: Less than or equal to

NE: Not equal to

In:in contains $in: [1,2,3,4]

Type: numeric type [Double 1, String 2, Object 3,array 4, binary data 5,object ID 7, boolean 8,date 9,null 10,reg 11,js Code 13 , 32-bit integer, timestamp 17,64-bit integer 18,]

exist: Presence $exist: False/true

Where:js query $where: ' this.sex=0 '

>db.demodb.find ({' sex ': {$in: [0,1]}})

Fuzzy query--using regular expressions

>db.demodb.find ({name:/^b.*/i})

Ubuntu System Installation MongoDB

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.