# go-server **Repository Path**: fan14/go-server ## Basic Information - **Project Name**: go-server - **Description**: 这是一个go服务 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-11-21 - **Last Updated**: 2026-01-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # mongoDB ```sql db.createCollection("notes", { validator: { $jsonSchema: { bsonType: "object", required: ["title", "content", "user_id"], // 必填字段 properties: { title: { bsonType: "string", maxLength: 100 }, // 标题最大长度100 content: { bsonType: "string" }, tags: { bsonType: "array", items: { bsonType: "string" } }, // 标签数组(字符串元素) is_public: { bsonType: "bool"}, // 默认公开 user_id: { bsonType: "objectId" } // 用户ID(ObjectId类型) } } }, validationLevel: "strict", // 严格验证(可选,默认strict) validationAction: "error" // 验证失败时抛出错误(可选,默认error) }); // 插入单条笔记(满足所有验证规则) db.notes.insertOne({ title: "MongoDB学习笔记-文档模型设计", // 字符串,长度≤100 content: "# MongoDB数据结构设计\n\n## 1. 文档模型特点\nMongoDB的文档模型采用BSON格式,支持嵌套结构...", // 字符串 tags: ["MongoDB", "数据库", "后端开发"], // 字符串数组 is_public: false, // 布尔类型 user_id: ObjectId("6562f7a8b1234567890abcda"), // ObjectId类型(需替换为实际用户ID) category_id: ObjectId("6562f7a8b1234567890abcdf"), // 可选字段(非验证必填) created_at: new Date("2025-11-27T10:00:00Z"), // 可选字段 updated_at: new Date("2025-11-27T15:30:00Z") // 可选字段 }); // 插入多条笔记(均满足验证规则) db.notes.insertMany([ { title: "Go语言Gin框架路由配置实战", // 标题长度合规 content: "# Gin框架基础路由\n\n1. 基本路由定义:\n```go\nr := gin.Default()\nr.GET(\"/hello\", func(c *gin.Context) { ... })\n```", tags: ["Go", "Gin", "Web框架"], // 字符串数组 is_public: true, user_id: ObjectId("6562f7a8b1234567890abcda"), // 关联同一用户 created_at: new Date("2025-11-26T09:00:00Z"), updated_at: new Date("2025-11-26T11:00:00Z") }, { title: "Redis缓存穿透解决方案", // 标题长度合规 content: "# Redis缓存穿透问题\n\n缓存穿透是指请求不存在的数据,导致每次都穿透到数据库...", tags: ["Redis", "缓存", "性能优化"], // 字符串数组 is_public: false, user_id: ObjectId("6562f7a8b1234567890abcda"), created_at: new Date("2025-11-25T14:00:00Z"), updated_at: new Date("2025-11-25T16:00:00Z") } ]); // 创建全文搜索索引(标题+标签) db.notes.createIndex({ "title": "text", "tags": "text" }); ```