is't possible to use unixtime with $dateToString
.
this is the schema:
var wifiSchema = mongoose.Schema({
ID: String,
Vendor: String,
SSID: String,
TimeStamp: {
date: Number,
},
AP: String,
MAC: String,
ID_frame: String,
RSSI: Number,
Type: String
}, { collection: 'wifiScan' });
var wifi = mongoose.model('wifi', wifiSchema);
and this is the mongoose function:
wifi.aggregate([
{$group:{_id:{"time" : "$TimeStamp.date"},uniqueCount: {$addToSet: "$MAC"}}},
{$project:{"time":1,uniqueCustomerCount:{$size:"$uniqueCount"}, yearMonthDayUTC: { $dateToString: { format: "%Y/%m/%d", date: new Date('$$TimeStamp.date') } } } },
{$sort:{'uniqueCustomerCount': -1 }}
]).limit(20).exec().then(notes => {
res.status(200).json({data:notes});
console.log(notes);
});
The problem that I get an error on converting the date variable from unix fo date format using $dateToString
, this is the result I get:
{ _id: { time: 1529235720000 },
uniqueCustomerCount: 26,
yearMonthDayUTC: '1970/01/01' } ]
I don't know why I get is as '1970/01/01
'. thanks for the help.
Second try:
I have tried this $project example also:
{$project:{"time":1,uniqueCustomerCount:{$size:"$uniqueCount"},"Time": { "$add": [ new Date(0), "$TimeStamp.date" ]} } },