Mongodb buffer time
Unanswered
Da_v_id posted this in #help-forum
Original message was deleted.
1 Reply
here is the model:
and here is the action:
export interface IAccount {
name: string;
icon: string;
balance: number;
color: string;
currency: string;
excludeFromStats?: boolean;
}
const AccountSchema = new Schema<IAccount>(
{
name: { type: String, required: true, message: '{VALUE} is not supported' },
icon: { type: String, required: true, message: '{VALUE} is not supported' },
balance: {
type: Number,
required: true,
message: '{VALUE} is not supported',
},
color: {
type: String,
required: true,
message: '{VALUE} is not supported',
},
currency: {
type: String,
required: true,
message: '{VALUE} is not supported',
},
excludeFromStats: {
type: Boolean,
required: true,
default: false,
message: '{VALUE} is not supported',
},
},
{ timestamps: true, collection: 'accounts' },
);
export const AccountModel =
mongoose.models.Account || mongoose.model('Account', AccountSchema);and here is the action:
`use server`
/**
* Adds a new account to accounts collection
* @param account Object containing account data
*/
export async function createAccount(account: IAccount) {
console.log('Starting createAccount');
console.log(AccountModel);
await clientPromise;
const dummyAccount = new AccountModel({
name: account.name,
icon: account.icon,
balance: account.balance,
color: account.color,
currency: account.currency,
excludeFromStats: account.excludeFromStats,
});
console.log('dummyAccount:', dummyAccount);
await dummyAccount.save();
console.log('doc saved:', dummyAccount);
}