I have get issue with startDate and endDate in Aggregate method, Help me for the same.
var startDate, endDate
startDate = new Date(0); // January 1, 1970
endDate = new Date();
endDate.setHours(23, 59, 59, 999)
db.collection.aggregate([
{
$match: {
$and: [
{
Role: 0,
},
{
CreatedAt: {
$gte: startDate,
$lte: endDate,
},
},
{
$or: [
{ Name: { $regex: new RegExp(searchKeyword, 'i') } },
{ Email: { $regex: new RegExp(searchKeyword, 'i') } },
{ Mobile: { $regex: new RegExp(searchKeyword, 'i') } },
],
}
]
}
},
{
$lookup: {
from: 'TaggedQrs',
localField: '_id',
foreignField: 'OwnerId',
pipeline: [
{
$project: {
_id: 0,
Address: 1,
Number: 1,
Description: 1,
LostItemName: 1,
Active: 1,
CreatedAt: 1,
},
},
{
$sort: {
CreatedAt: -1,
},
},
],
as: 'TaggedQrs',
},
},
{
$addFields: {
TotalQrs: { $size: '$TaggedQrs' },
},
},
{
$project: {
_id: 1,
Name: 1,
Email: 1,
Mobile: 1,
Active: 1,
CreatedAt: 1,
TaggedQrs: 1,
TotalQrs: 1,
},
},
{
$sort: {
CreatedAt: -1,
},
},
{
$facet: {
Owners: [
{ $skip: (1- 1) * 10},
{ $limit: 10},
],
TotalCount: [{ $count: 'count' }],
},
},
{
$unwind: '$TotalCount',
},
{
$project: {
Owners: 1,
TotalCount: '$TotalCount.count',
TotalQrs: 1,
}
}
]).toArray()