I have the following MongoDB aggregate operation which is working fine but it also seems to be returning NULL values.
How can I ignore NULL values against projectIP field?
db.inventory.aggregate(
[
{ $match: {projectIP: { $exists:true }}},
{ $project: {projectIP: "$projectIP",_id : 0}},
{ $group: {_id: "$projectIP"}},
{ $sort: {projectIP: 1}}
];
)
{ $match: { projectIP: { $exists:true }}}$sort{}$sort. This should be the top of the pipeline above$projectnullvalues. Add this as well{ $match: { projectIP: { $exists:true, $ne: null }}}by replacing the first stage in your query