Mongo Sample find query
db.getCollection("user").find(
{
"username" : "kia"
},
{//projections
"username": 1.0, //1.0 means include
"address": 1.0,
"phone": 1.0
}
).sort(
{
"createDate": -1.0 //-1.0 is descending order
}
);
Aggregate query
db.getCollection("collectionName").aggregate([
{"$match": { "col1":"colValue", "date": {
"$gte": ISODate("2021-01-01T00:00.000+0000"),
"$gte": ISODate("2021-01-02T00:00.000+0000")
}
}
},
{"$group": {"_id":"colId", "count": {"$sum":1}}}
]);
Comments