Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanleantking/1a0972ed0c1a5a7bf4125a1518d8501d to your computer and use it in GitHub Desktop.
Save vanleantking/1a0972ed0c1a5a7bf4125a1518d8501d to your computer and use it in GitHub Desktop.
câu query lấy tất cả các field của collection mongo
db.getCollection("report_detail").aggregate([
{'$match':{'date':'2023-03-01'}},
{ "$project": {
"hashmaps": { "$objectToArray": "$$ROOT" }
} },
{ "$group": {
"_id": null,
"fields": { "$addToSet": "$hashmaps.k" }
} },
{ "$project": {
"keys": {
"$setDifference": [
{
"$reduce": {
"input": "$fields",
"initialValue": [],
"in": { "$setUnion" : ["$$value", "$$this"] }
}
},
["_id"]
]
}
}
}
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment