Skip to content

Instantly share code, notes, and snippets.

@bogoslavskiy
Created March 5, 2020 15:30
Show Gist options
  • Save bogoslavskiy/ff94d7bd66dcae745e43a453106b369f to your computer and use it in GitHub Desktop.
Save bogoslavskiy/ff94d7bd66dcae745e43a453106b369f to your computer and use it in GitHub Desktop.
import * as mongoose from 'mongoose';
function timestamp() {
return +new Date();
}
export interface MessageDocument extends mongoose.Document {
sender_id: string;
senderName: string;
text: string;
date: number;
}
const schema = new mongoose.Schema<MessageDocument>(
{
sender_id: {
type: String,
required: true,
},
senderName: {
type: String,
required: true,
},
text: {
type: String,
required: true,
},
date: {
type: Number,
default: timestamp
}
},
{ versionKey: false }
);
export default mongoose.model<MessageDocument>('Message', schema);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment