R
R
rodik1310982018-11-19 19:20:39
MongoDB
rodik131098, 2018-11-19 19:20:39

How to store express + mongoDB static information?

I am writing an application on a bunch of vue + express.js + mongoose, the question arose of how to store static content such as text and paths to images for a slider, etc. In the future, I plan to fasten the admin panel, in which I am going to add the ability to edit this content, but I don’t know how to organize the database structure.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Mensky, 2018-11-22
@men232

You can try the following options.
1. Upload user content to AWS and save to url base.
2. Upload to a local folder (for example /public) and also store the url in the database.
For the second option, I suggest not using native file names to avoid overwriting on disk.
Can be generated using the formula: sha1(Date.now() + Math.random() + ORIGIN_FILE_NAME) + file extension.
Regarding the structure, if this is the content of the main page and not a specific post. You can organize a key-value collection for configs. For example

db.site_configs.find()
{
    _id: "landing.slider",
    value: [
        { "title": "IMG 1", url: "http://.../image1.jpg" },
        { "title": "IMG 2", url: "http://.../image2.jpg" }
    ]
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question