Introduction | The natural compatibility of MongoDB and JavaScript makes using MongoDB under Node.js extremely comfortable. We usually use ORM tools like mongoose to operate MongoDB. However, manually viewing the database is still useful in many scenarios, such as debugging relationships between models, clearing user tables, and resetting the database. |
# View database
show dbs
# Switch database
use mydatabase
# Delete the current database
db.dropDatabase()
# View Collection
show collections
# Delete collection
db.users.drop()
db.users.insert({ name:'harttle', url:'http://harttle.com' })
# Query all
db.users.find()
# Conditional query
db.users.find({ name:'harttle' })
# Indented output
db.users.find().pretty()
db.users.update({ name:'harttle' }, { url:'http://harttle.com' })
# Delete all
db.users.remove({})
# Conditional deletion
db.users.remove({ url:'http://harttle.com' })
The above is the detailed content of Common MongoDB operation commands. For more information, please follow other related articles on the PHP Chinese website!