1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
| use ecommerce
db.products.insertMany([ { _id: ObjectId(), name: "iPhone 13 Pro", sku: "IP13P-256-BLK", price: 8999.00, category: "智能手机", brand: "Apple", attributes: { color: "石墨黑", storage: "256GB", screen_size: "6.1英寸" }, stock: { total: 150, reserved: 20, available: 130 }, tags: ["新品", "旗舰", "热卖"], ratings: { average: 4.8, count: 1250 }, is_active: true, created_at: new Date(), updated_at: new Date() }, ])
db.users.createIndex({ email: 1 }, { unique: true }) db.users.createIndex({ phone: 1 }, { sparse: true }) db.users.createIndex({ "addresses.city": 1 })
db.users.insertOne({ username: "tech_guru", email: "user@example.com", phone: "13800138000", profile: { real_name: "张三", avatar: "https://example.com/avatar.jpg", gender: "male", birthday: new Date("1990-01-01") }, addresses: [ { id: 1, recipient: "张三", phone: "13800138000", province: "北京市", city: "北京市", district: "朝阳区", detail: "某某街道123号", is_default: true } ], membership: { level: "gold", points: 12500, expires_at: new Date("2024-12-31") }, created_at: new Date(), last_login: new Date() })
db.orders.createIndex({ user_id: 1, created_at: -1 }) db.orders.createIndex({ order_no: 1 }, { unique: true }) db.orders.createIndex({ status: 1 })
db.orders.insertOne({ order_no: "ORD202401150001", user_id: ObjectId("..."), status: "pending", items: [ { product_id: ObjectId("..."), sku: "IP13P-256-BLK", name: "iPhone 13 Pro", quantity: 1, unit_price: 8999.00, subtotal: 8999.00, snapshot: { } } ], amount: { subtotal: 8999.00, shipping: 0.00, discount: 200.00, total: 8799.00 }, payment: { method: "alipay", transaction_id: "202401152100100...", paid_at: new Date(), amount: 8799.00 }, shipping: { address_id: 1, courier: "SF Express", tracking_no: "SF1234567890", shipped_at: null, estimated_delivery: new Date("2024-01-18") }, created_at: new Date(), updated_at: new Date() })
|