Created
March 24, 2023 09:51
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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