A
A
Artyom2020-03-27 14:38:39
MongoDB
Artyom, 2020-03-27 14:38:39

How to output string from mongodb?

Hello everyone, I added data to the database that I can’t display correctly on ejs!
Here's how I get data from the database:

app.get('/ads/check',async (req,res,next) => {
    await Ads.find({}).then(result => {
        const login = req.session.login
        res.render('check', {
        title: "Ваша рекламa на сайте!",
        login: login,
        result
        })
    })
})


Here is the db structure:
var ads = new Schema({
    name: String,
    iframe: String
})
var Ads = mongoose.model('Ads', ads)


How can I now display name and iframe on the ejs page?
Ie how to transfer not an object but a string?

I am using node js express js and mongoose stack

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
drawnofmymind, 2020-03-27
@drawnofmymind

Const result = await Ads.find() , and result in render?

H
hzzzzl, 2020-03-27
@hzzzzl

not entirely sure about the ejs syntax, but

<%- [вот сюда имя строковой переменной с кодом] %>

<%- result.iframe %>

and then the iframe code should simply be inserted into the html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question