Hi,
I have a MongoDB collection named “histoValues” whose fields are:
_id , ctype, cname, pname, instrument, timestamp, value
I want to select distinct ctype/cname/pname for a given instrument and range of dates (fromDate, toDate).
In SQL, the query I would do is:
SELECT DISTINCT(ctype, cname, pname)
FROM histoValues
WHERE (timestamp >= fromDate and timeStamp <= toDate)
AND instrument = 35
GROUP BY ctype, cname, pname
In MongoDB Compass tool, I firstly tried to group on ctype, without any $match.
In SQL it would be :
SELECT DISTINCT(ctype)
FROM histoValues
GROUP BY ctype
In Compass, I used the $group aggregation operator and entered:
{
_id: “$ctype”
}
In the “output after $group stage” window, there is the following result:
_id: “Axis”
while I have three different ctype values in my collection.
What am I doing wrong ?
And how do I add fields in my $group operator ?
Thanks a lot for your help