-1

I've been looking at some StackOverflow cases such as this case, but I cannot find an example with a document structure close to this one.

Below is an example of one document within my collection artistTags. All documents follow the same structure.

{
  "_id": ObjectId("5500aaeaa7ef65c7460fa3d9"),
  "toptags": {
    "tag": [
      {
        "count": "100",
        "name": "Hip-Hop"
      },
      {
        "count": "97",
        "name": "french rap"
      },
      ...{
        "count": "0",
        "name": "seen live"
      }
    ],
    "@attr": {
      "artist": "113"
    }
  }
}

1) How can I find() this document using the "artist" value (here "113")?

2) How can I retrieve all "artist" values having a specific "name" value (say "french rap") ?

Community
  • 1
  • 1
guzu92
  • 737
  • 1
  • 12
  • 28
  • 1) `db.collection.find({"toptags.@attr.artist": "113"})` – chridam Mar 11 '15 at 23:20
  • 1
    thanks ! as you can see I'm a beginner :-), do you want *answer* to win some credits or can I answer myself ? – guzu92 Mar 12 '15 at 19:09
  • That's ok, you can post the solution that worked for you, others may find it useful :) – chridam Mar 12 '15 at 21:27
  • 1
    You should read the official [getting started guide](https://docs.mongodb.org/getting-started/shell/) that is very simple to understand and will provide you with this kind of informations. – AntoineB Mar 22 '16 at 22:30

1 Answers1

2

Referring to chridam answer here above:

db.collection.find({"toptags.@attr.artist": "113"})
Community
  • 1
  • 1
guzu92
  • 737
  • 1
  • 12
  • 28