D
D
Devero972021-02-20 18:51:10
Node.js
Devero97, 2021-02-20 18:51:10

How to save html markup with text in mongodb?

I put html markup in the textarea tag and save it to a variable. Then I send and save to the database. But instead of such, for example, the code: Hello, this <h2>Hello</h2> is stored in the database. And when displaying on the front, I can't display the text normally. It is the preservation that occurs as if with the conversion. When I insert the code into the database myself, without using textarea, everything works fine.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniil Vasilyev, 2021-02-22
@hello_my_name_is_dany

See how the data was saved through the mongodb cli. If it's just Hello, then you have a strip of html tags, it should be disabled for this HTTP save request. If it is preserved as it should, then you need to look at how you output to the front, many frameworks make strip tags, so look for your framework how you can output without it. And if you use the DOM API, then you need to display it through innerHtml

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question