V
V
vita_run2018-06-18 21:38:10
JavaScript
vita_run, 2018-06-18 21:38:10

How to implement search by incomplete occurrence?

The entry has the name `titlePhoto`, which is stored as an array. I'm trying to search for an incomplete name. How to do it right? Throws a `photos is not defined` error.
Search Form:

<form class="search-form" action="/search-form" method="post">
         <input class="search-input" placeholder="Введите название" type="search" value="" name="search" id="inputSearch">
         <label for="search" class="search-label">
            <img src="/static/images/icons/search.svg">
         </label>
    </form>

post handler
app.post('/search-form', function (req, res) {
        var inputSearch = req.body.search;
        Photo.aggregate([
            {"$match": {
                "titlePhoto": {"$regex": inputSearch, "$options": "i"}
                }}
        ]);
        res.render('index.ejs', {photoList: photos});

get handler
app.get('/', function (req, res) {
        Promise.all([
            Photo.find({}),
            Sight.find({}),
            Categories.find({})
        ]).then(function(data) {
            res.render('index.ejs', {photoList: data[0], sights: data[1], categories: data[2], isAuth: req.isAuthenticated()});
        } );
    });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anubis, 2018-06-19
@Anubis

I see a reference to the photos variable in the post handler listing
I don't see its declaration
Maybe const photos = Photo.aggregate...?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question