MongoDB Simple operation

Source: Internet
Author: User
Tags mongodb query mongodb tutorial

1. Perform Mongod.exe server startup database and log that can be followed by parameter description.

eg

Mongod.exe--bind_ip 127.0.0.1--logpath "F:\data\dbConf\mongodb.log"--logappend--dbpath "F:\data\db"--port 19901-- ServiceName "MONGODB1"--servicedisplayname "Mongodball"--install


2. Perform Mongo.exe Client connection


View all databases: Show DBS

Syntax format for creating a database: Use database_name

Delete Current database: Db.dropdatabase ()

Switch to database: use database_name

Delete collection: Db.collection.drop ()

MongoDB uses the Insert () or Save () method to insert a document into the collection:

Db. Collection_name.insert (document)

MongoDB uses the update () and Save () methods to update the documents in the collection:

The update () method is used to update a document that already exists. The syntax format is as follows:

Db.collection.update (

<query>,//query:update the query condition, similar to the SQL update query inside the where.

<update>,//update:update objects and some updated operators (such as $, $inc ... ) can also be understood as the SQL update query within the set after the

{

Upsert: <boolean>,//upsert: Optional, this parameter means that if there is no record of update, insert objnew,true as INSERT, default is False, do not insert.

Multi: <boolean>,//multi: Optional, 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.

writeconcern: <document>//writeconcern: Optional, throws an exception level.

 }

)

The Save () method replaces an existing document with an incoming document. The syntax format is as follows:

Db.collection.save (

<document>,

{

Writeconcern: <document>

 }

)

Db.col.update ({' title ': ' MongoDB Tutorial '},{$set: {' title ': ' MongoDB '}})

MongoDB Delete Document

Parameter description:

Document: Documentation data.

Writeconcern: Optional, throws an exception level.

The basic syntax format for the Remove () method is as follows:

Db.collection.remove (

<query>,

<justOne>

)

Remove all data: Db.col.remove ({})

The syntax format for MongoDB query data is as follows:

Db. Collection_name.find ()

Read data in an easy-to-read manner

Db.col.find (). Pretty ()

Action format example of a similar statement in an RDBMS

equals {<key>:<value>}Db.col.find ({"By": "Rookie Tutorial"}). Pretty ()where by = ' Rookie Tutorial '

Less than {<key>:{$lt: <value>}} db.col.find ({"likes": {$lt:)}. Pretty () Where likes < 50

Less than or equal to {<key>:{$lte: <value>}} db.col.find ({"likes": {$lte:]}). Pretty ( ) where likes <= 50

Greater than {<key>:{$gt: <value>}} db.col.find ({"likes": {$gt:}}). Pretty ()where Likes > 50

Greater than or equal to {<key>:{$gte: <value>}} db.col.find ({"likes": {$gte:]}). Pretty ( ) where likes >= 50

Not equal to {<key>:{$ne: <value>}} db.col.find ({"likes": {$ne:}}). Pretty ()where Likes! = 50

The condition operators in MongoDB are:

(>) Greater than-$GT

(<) less than-$lt

(>=) greater than or equal to-$gte

(<=) less than or equal to-$lte

Db.col.find ({"likes": {$gt: 100}})

Similar to the SQL statement:

Select * from Col where likes > 100;

The above is I watch the site on the side of the record down.

This article is from "Walking Taihang Yan Zhao" blog, please be sure to keep this source http://chaoslee.blog.51cto.com/10643967/1856759

MongoDB Simple operation

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.