Skip to content

List tags #99

Answered by rodrigoddalmeida
haf asked this question in Help
Jan 22, 2023 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

To fetch a list of all product tags, you can query the /products/:group endpoint with an aggregation like this:

{
  "aggregate": [
    {
      "$unwind": "$tags"
    },
    {
      "$group": {
        "_id": null,
        "allTags": {
          "$addToSet": "$tags"
        }
      }
    },
    { "$project": { "_id": 0, "allTags": 1 }}
  ]
}

The tags field in our base Product model is a simple list of strings, which may not be the best fit if you want a more robust reference between tags or tags -> products - that may work better with categories and attributes.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@haf
Comment options

Answer selected by haf
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants