Non-relational database
- command is case-sensitive; command Terminator is carriage return (unlike MySQL)
MongoDB Configuration
sudo service mongodb start
mongo
MongoDB Basic Concept
集合
A concept that corresponds to a relational database 表
, creating a collection: db.createCollections("<集合名>")
; Deleting a collection: db.<集合名>.drop()
; getting all the collections:show collections
文档
The concept of a relational database 记录
, MongoDB's documentation, is represented by the bson
loosely structured data structure of the class JSON (JSON-upgraded version)
Inserting a document into the collection
1. Useinsert()
e.g.:db.<集合名>.insert([{name:"hello",email:"[email protected]"},{name:"world",email:"[email protected]"}])
2. Use save()
(note with the Insert () difference, save () when inserting data, the collection will be created automatically if the collection does not exist)
e.g.:db.<集合名>.save([{name:"hello",email:"[email protected]"},{name:"world",email:"[email protected]"}])
数据库
1. Create a database:use <数据库名>
2. View the currently connected database:db
3. View all databases:show dbs
4. Destroy the database: switch to the database that you want to destroy, and then executedb.dropDatabase()
Basic operations for MONGODB databases and collections