First open mongodb in terminal.
one. Database creation and opening.
use DATABASE_NAME (the name of the database); without this database is to create, there is to open.
example:
>use text switched to db text > db text
This creates a database with name=text.
two. Deletion of the database.
db.dropDatabase(); delete the current database.
example:
>use text switched to db text >db.dropDatabase()
This deletes the text database.
three. Database insert information.
db.COLLECTION_NAME.insert(documnet).
COLLECTION_NAME: Insert the name of the collection.
document: the inserted data.
>use text switched to db text >db.users.insert({'name':'阿大','age':20})
In this way, {'name':'Ada','age':20} is inserted into the users collection.
Four. Database data update.
db.COLLECTION_NAME.update(<condition>, <data>, <insert without data>)
example:
>db.users.update({'name':‘阿大},{'age':24}) >db.users.find() {'name':'Ada,'age':24}
5. Database query.
db.COLLECTION_NAME.find();
six. Deletion of database data.
db.COLLECTION_NAME.remove(<conditions for deleting documents>,<deleting documents (true or 1 are both values to delete a piece of data)>,<throw error level>);
The above conditions are optional.