I am using mongodb and I am having challenges saving.
My Schema is
const transaction = new Schema({
sender: {
type: ObjectId,
default: null,
transaction_type: {
type: String,
enum: transaction_types,
default: null
}
},
recipient: {
type: ObjectId,
default: null,
transaction_type: {
type: String,
enum: transaction_types,
default: null
}
},
coins: {
type: Number
},
fee: {
type: Number,
default: 0
},
}, {
timestamps: {createdAt: 'created_at', updatedAt: 'updated_at', deleted_at: 'deleted_at'}
})
In my controller, I am doing this
await WalletTransaction.create({
sender: user._id,
recipient: recipient,
coins: coins
});
How do I save the transaction type alongside the sender and recipient.
Thanks a lot
2
Answers
I had to change my model to
and on saving, I did this
Is
WalletTransaction
the model of thetransaction
schema? you may do this to save the document: