The MONGO shell is a JavaScript interface used to connect MongoDB, providing users with the means to query and manipulate data in MongoDB, and to manage MongoDB.
start and automatically connect to a MongoDB instance:The default installation in "/usr/bin/", with "which" command can be viewed to: # which Mongo/usr/bin/mongo so you can run directly: # MONGO MongoDB Shell version:3.2.3 connecting To:test ... The default is to connect to port 27017 on localhost and use the test database by default.
to switch to a different database:> Use <db_name>
Insert (Create):Insert Command Reference: https://docs.mongodb.org/manual/tutorial/insert-documents/
> Db.<collection_name>.insert ({key:value}); # "DB" indicates the currently used db. For example: > Db.testCollection.insert ({name: "Xu"}) Writeresult ({"ninserted": 1})
query (Read):Query Command reference: https://docs.mongodb.org/manual/tutorial/query-documents/
> Db.<collection_name>.find () #没带条件表示查询所有, default returns 20 such as: > Db.testCollection.find () {"_id": ObjectId ("56ca7c 37012557f8f72c9a1f ")," name ":" Xu "}
Landscaping query Result: > Db.myCollection.find (). Pretty ()
Modify (Update):Modify Command Reference: https://docs.mongodb.org/manual/tutorial/modify-documents/
> db.<collection_name>.update ({key: "value"}, {key: "NewValue"}) # (the first parameter is the query condition, the second parameter is the content of the update)
For example: > Db.testCollection.update (... {Name: "Xu"}, ... {Name: "Clement-xu"}) Writeresult ({"nmatched": 1, "nupserted": 0, "nmodified": 1}) > Db.testCollection.find (). Pretty () {"_id": objecti D ("56ca7c37012557f8f72c9a1f"), "name": "Xujijun"}
Remove (delete):Delete Command reference: https://docs.mongodb.org/manual/tutorial/remove-documents/
> Db.<collection_name>.remove ({key: "value"}) #如果不带参数, delete all
For example: > Db.testCollection.remove (... {Name: "Clement-xu"}) Writeresult ({"nremoved": 1})
Exit MONGO Shell: > Quit () or exit or <Ctrl-c>
Graphical (GUI) client:Robomongo:https://robomongo.org need to modify the MongoDB configuration file, remove the IP bindings: # vi/etc/mongod.conf Comment out this sentence: bindip:127.0.0.1 then restart the service: # Ser Vice Mongod restart
Specify IP and port connections after starting Robomongo:
Note: The latest version of Robomongo has canceled the SSH tunnel function (unknown). Do what you need, such as through SECURECRT.
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.