I will have 2 data schemas
User Schema will have 4 key value pairs
backend auth user schema
{
"name": string,
"email": string,
"password": string
}
full code
const UserSchema = new mongoose.Schema({
name: {
type: String,
required: true,
},
email: {
type: String,
required: true,
unique: true,
},
password: {
type: String,
required: true,
},
});
const User = mongoose.model('user', UserSchema);
export default User;
Transactions Schema will have 6 key value pairs
{
"_id": string,
"amount": number,
"type": string,
"category": string,
"description": string,
"date": string
}
full code - transactions frontend schema will be in a form
import mongoose from "mongoose";
const TransactionSchema = new mongoose.Schema({
//transactions are identified by users from the userschema in mongoose db
user: {
type: mongoose.Schema.Types.ObjectId,
ref: "user",
required: true,
},
amount: {
type: Number,
required: true,}
type: {
type: String,
enum: ["income", "expense"],
},
category: {
type: String,
},
description: {
type: String,
}
date: {
type: Date,
default: Date.now,
},
});
const Transaction = mongoose.model('transaction', TransactionSchema)
export default Transaction;
Might add timestamps for both schemas