Answer the question
In order to leave comments, you need to log in
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>
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});
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question