MongoDB Learning Summary (i)

Source: Internet
Author: User
Tags mongo shell

About the default settings for the MOGODB database:
1. The port default setting is: 270172. The database file location defaults to: c:/data/db, it is recommended to modify to a different disk location, you must create the Data/db folder at the root of the disk the default logging mode of the 3.MONGODB database is overridden to overwrite the way, We recommend that you write the log by using the Append method: Mongod--logpath "D:/data/log/mongodb.log"--logappend
MONGO Shell Operation command: 1. Connect to MongoDB Database
MONGO--host hostname/ip--port 27017 [DatabaseName] Example: MONGO--host 172.0.0.1--port 27017 Mydbs
2. Collection Operations
Db.student.drop ();//delete Student this collection
3. Document operations
Focus: Learn $inc/$set/$unset/$push/$pop/upsert modifier//Insert document Db.student.insert into student collection ({"Name": "Zhangsan"});// The query document uses find ();d b.student.find ();//update id=58d4ccd4126ab1e4ca76aa73 's document, modify or add its name key value to Db.student.update ({"_id": ObjectId ("58d4ccd4126ab1e4ca76aa73")},{"$set": {"name": "Xiaoming"}});//Modify the document using Update () db.student.update ({"Name": "Xiaoming"},{"$set": {"Age": +});d B.student.update ({"Name": "Xiaoming"},{"$set": {"name": "Dragon"}}); Result: {"_id": ObjectId ("58d4ccd4126ab1e4ca76aa73"), "name": "Dragon", "age": 23}//Format Document when querying documents Db.student.find (). Pretty ();                                  {    "_id": ObjectId ("58d4ccd4126ab1e4ca76aa73"),     "name": "Xiaoming",     "age": 23}// Delete Document syntax: Db.collection.remove (condition, {justone: <boolean>,writeconcern: <document>}) query: (optional) The condition of the deleted document. Justone: (optional) If set to TRUE or 1, only one document is deleted. Writeconcern: (optional) the level at which the exception is thrown. Example: Db.student.remove ({"Name": "Dragon"},{"Justone": True, "Writeconcern": true});
4. Conditional operators
$lt (<), $gt (>), $gte (>=), $lte (<=)
5.mongodb Fuzzy Query
Db.student.find ({"name": {"$regex": "zhangsa*", "$options": "I"}});

Result: {"_id": ObjectId ("58d4da0a126ab1e4ca76aa74"), "name": "Zhangsan"}

Db.student.insert ({"Name": "Cheng Long", "age": All, "adress": "Beijing"}); Db.student.find ({name:{$regex: "Into", $options: "I"}});

Result: {"_id": ObjectId ("58d508b109d615ae79c96930"), "name": "Cheng Long", "age": All, "adress": "Beijing"}

MONGO--host 172.0.0.1--port 27017 mydbsdb.student.find ({"name": {$regex: ' Dragon ', $options: ' I '}};d B.test_info.find ({" Tname ": {$regex:/Jackie./i}});

This article is from my Tech blog blog, so be sure to keep this source http://zhufangmin.blog.51cto.com/10913615/1910306

MongoDB Learning Summary (i)

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.