名称: mongodb 描述: MongoDB 数据库模式设计、聚合管道、索引策略与性能优化。 允许工具: 读取、写入、编辑、Bash、Glob、Grep
MongoDB 技能
提供 MongoDB 数据库设计与操作的专家级协助。
能力范围
- 设计文档模式
- 构建聚合管道
- 创建最优索引
- 实施数据建模模式
- 配置复制与分片
聚合管道示例
const results = await collection.aggregate([
{ $match: { status: 'active' } },
{ $group: { _id: '$category', total: { $sum: '$amount' } } },
{ $sort: { total: -1 } },
{ $limit: 10 },
]).toArray();
索引示例
// 复合索引
await collection.createIndex({ userId: 1, createdAt: -1 });
// 文本索引
await collection.createIndex({ title: 'text', content: 'text' });
目标流程
- mern-stack-开发
- 数据库设计
- 后端开发