mongodb
SolidMongoDB 数据库管理
AI & Automation 1 stars
0 forks Updated yesterday Apache-2.0
Install
Quality Score: 79/100
Stars 20%
Recency 20%
Frontmatter 20%
Documentation 15%
Issue Health 10%
License 10%
Description 5%
Skill Content
# MongoDB 数据库管理
## 概述
MongoDB 操作、索引优化、分片集群等技能。
## 连接管理
```bash
# 本地连接
mongosh
mongosh --port 27017
# 远程连接
mongosh "mongodb://hostname:27017"
mongosh "mongodb://user:password@hostname:27017/database"
# 副本集连接
mongosh "mongodb://host1:27017,host2:27017,host3:27017/database?replicaSet=rs0"
# 执行脚本
mongosh script.js
mongosh --eval "db.collection.find()"
```
## 基础操作
### 数据库操作
```javascript
// 显示数据库
show dbs
// 切换/创建数据库
use mydb
// 删除数据库
db.dropDatabase()
// 数据库统计
db.stats()
```
### 集合操作
```javascript
// 显示集合
show collections
// 创建集合
db.createCollection("users")
// 删除集合
db.users.drop()
// 集合统计
db.users.stats()
```
### CRUD 操作
```javascript
// 插入
db.users.insertOne({ name: "John", age: 30 })
db.users.insertMany([{ name: "Jane" }, { name: "Bob" }])
// 查询
db.users.find()
db.users.find({ age: { $gt: 25 } })
db.users.findOne({ name: "John" })
db.users.find().limit(10).skip(20).sort({ age: -1 })
// 更新
db.users.updateOne({ name: "John" }, { $set: { age: 31 } })
db.users.updateMany({ age: { $lt: 18 } }, { $set: { status: "minor" } })
db.users.replaceOne({ name: "John" }, { name: "John", age: 32 })
// 删除
db.users.deleteOne({ name: "John" })
db.users.deleteMany({ status: "inactive" })
```
## 索引管理
```javascript
// 查看索引
db.users.getIndexes()
// 创建索引
db.users.createIndex({ email: 1 }) // 升序
db.users.createIndex({ name: 1, age: -1 }) // 复合索引
db.users.createIndex({ email: 1 }, { unique: true }) // 唯一索引
db.users.createIndex({ location: "2dsphere" ...
Details
- Author
- ryukyagamilight
- Repository
- ryukyagamilight/terminal-skills
- Created
- 5 months ago
- Last Updated
- yesterday
- Language
- N/A
- License
- Apache-2.0
Integrates with
Similar Skills
Semantically similar based on skill content — not just same category
AI & Automation Solid
elasticsearch
Elasticsearch 集群管理
1 Updated yesterday
ryukyagamilight AI & Automation Solid
redis
Redis 数据库管理
1 Updated yesterday
ryukyagamilight API & Backend Listed
mongodb
Work with MongoDB databases using best practices. Use when designing schemas, writing queries, building aggregation pipelines, or optimizing performance. Triggers on MongoDB, Mongoose, NoSQL, aggregation pipeline, document database, MongoDB Atlas.
2 Updated yesterday
Makiya1202