Hello. The site has a search form, and if the field is not filled, I transfer to the search object null . On the server should go search for the specified criteria, but how to cancel the search for a particular key if it is null? An example of creating a search object:
searchArray = [form.elements.ageFor.value || null, form.elements.ageTo.value || null, form.elements.country.value || null, form.elements.city.value || null, form.elements.topics.value || null ]; function CreateSearthObject() { this.ageFor = searchArray[0]; this.ageTo = searchArray[1]; this.male = userMale || null; this.country = searchArray[2]; this.city = searchArray[3]; this.topics = searchArray[4]; } Then it flies to the server and there:
socket.on('search', function(requestID, searchData){ db.collection('users').find(age: {$gte : searchData.age, $lte : searchData.age}).toArray(function(error, docs){ io.emit('displayAllUsers', docs, requestedID); }); //Как в find отключить поиск по age если в searchData оно равно null?
undefinedinstead? - Qwertiy ♦