I am trying to find a list of documents using the $in
operator to fetch data only for todays date when I am passing to the server array with todays data, but the method just ignore it and return list of documents using the rest of the parameters I attached without the $in
one that supposed to filter data only for today.
Front:
fetchTodaysCoordsFromServer = () => {
let today = new Date().toString().split(' ');
today = today.slice(0, 4);
this.clearSumAll();
let placeHolderForData = [];
axios
.post('https://server.com/fetchtodayscoords', {
type: this.state.type,
userName: this.props.userName,
today: today
})
.then((res) => {
res.data.map((details) => {
placeHolderForData.push(details.sumAll)
})
this.setState({
sumAll:placeHolderForData
})
})
.catch(() => {
console.log('there was problem fetching todays coords')
})
}
BACK:
router.post('/', (req, res) => {
if (req.body.type === 'user') {
MapData.find(
{
date: { $in : req.body.today},
show: true,
userName: req.body.userName
}, // find all documents that contains today date
(err, data) => {
if (err) {
console.log('couldnt fetch coords: ' + err);
res.send(err);
}
if (data) {
console.log(`this is data from user ${data}`);
res.send(data);
}
}
);
}
})
MODEL:
let MapData = mongoose.model('mapData', {
userName: {
type: String
},
date: {
type: Array
},
show: {
type: Boolean
}
});
EXAMPLE OF DOCUMENT:
{
"_id": {
"$oid": "5b1673c8ba283d0014750346"
},
"date": [
"Tue",
"Jun",
"05",
"2018"
],
"userName": "user1",
"show": true,
"__v": 0
}