Home > System Tutorial > LINUX > body text

Common MongoDB operation commands

WBOY
Release: 2024-01-05 19:56:11
forward
527 people have browsed it
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.
This article lists these commonly used MongoDB commands. MongoDB documentation: https://docs.mongodb.com/常用的 MongoDB 操作命令 Database Operation

# View database

show dbs
Copy after login

# Switch database

use mydatabase
Copy after login

# Delete the current database

db.dropDatabase()
Copy after login
Collection operations

# View Collection

show collections
Copy after login

# Delete collection

db.users.drop()
Copy after login
Document operations Insert document
db.users.insert({
    name:'harttle',
    url:'http://harttle.com'
})
Copy after login
Query Document

# Query all

db.users.find()
Copy after login

# Conditional query

db.users.find({
    name:'harttle'
})
Copy after login

# Indented output
db.users.find().pretty()

Update documentation
db.users.update({
    name:'harttle'
}, {
    url:'http://harttle.com'    
})
Copy after login
Delete Document

# Delete all

db.users.remove({})
Copy after login

# Conditional deletion

db.users.remove({
    url:'http://harttle.com'
})
Copy after login

The above is the detailed content of Common MongoDB operation commands. For more information, please follow other related articles on the PHP Chinese website!

source:linuxprobe.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!