16 lines
575 B
JavaScript
16 lines
575 B
JavaScript
|
// userModel.js
|
||
|
// 使用者的資料結構定義
|
||
|
|
||
|
const mongoose = require('mongoose');
|
||
|
|
||
|
const userSchema = new mongoose.Schema({
|
||
|
userId: { type: Number, required: true }, // Telegram 使用者 ID
|
||
|
username: String, // 使用者名稱(可選)
|
||
|
groupId: { type: Number, required: true }, // 所在群組 ID
|
||
|
lastActive: Date, // 最後發言時間
|
||
|
});
|
||
|
|
||
|
userSchema.index({ userId: 1, groupId: 1 }, { unique: true }); // 避免重複記錄
|
||
|
|
||
|
module.exports = mongoose.model('User', userSchema);
|