Closed skorphil closed 7 months ago
example how to separately store mongoDb model
it is good practice to cache mongo connection. (to prevent creating connections on each operation). For this author suggests use of global
object in nodejs
Seems like it is not necessary to have additional caching logic, because mongoose has connection pool
Caching pattern is used in serverless functions: https://github.com/Automattic/mongoose/discussions/14425#discussion-6340493
Official docs on serverless function https://mongoosejs.com/docs/lambda.html
Previously i came up to quotes structure as:
quotes: [
{
usd: [
{ amd: 401.94591125 },
{ brl: 4.94543198 },
{ usd: 1 },
],
},
]
but this seems like not best structure due to dynamic key names (currencies). This is not convenient for schemas. I.e. for mongoose scheme.
Better to use static key names:
quotes: [
{
baseCurrency: "usd",
rates:[
{currency: "brl", rate: 4.94543198},
{currency: "amd", rate: 401.94591125},
]
}
]
MongoDB supports subdocuments, so for example quotes can be stored separately as a subdocument of record. For the sake of simplicity will not be use em and store whole nested record inside single document
Implemented base functionality.
utils/mongooseConnect
- handle mongoose connection
serverActions/appendRecord
- handle reformatting of FormData and submitting to db
models/record
- record model for mongoose
For the future - maybe i should group all stuff in feature-based folder, like
features/mongoAppendRecord
Remaining