-1

I have a collection "testcase" like this, Test Builds have many Test Case Logs and Test Case Logs have many tags. For example I have a query where tags should have "tag1".

db.test_builds.find({"logs.tags" : "tag1"})

The problem is that it gets all the test case logs of the test builds. But I only wanted test case logs where the "tag1" exists.

For example:

{
  "name" : "TestBuild1"
  "logs: [
    {"name" : "Log1"
    "tags" : ["tag1","tag2"]},
    {"name" : "Log2"
    "tags" : ["tag3","tag4"]}
  ]
}

The query above returns the whole test build, but I only want to get Test Build with "Log1", but not "Log2". How is this possible?

rayne23
  • 1
  • 2
  • Exact duplicate of http://stackoverflow.com/questions/3985214/mongodb-extract-only-the-selected-item-in-array, which lists several answers. – Dan Dascalescu Nov 04 '12 at 13:46

1 Answers1

0

In MongoDB, you can't extract part of elements from the array. You need to filter it out at client side or do map/reduce as explained here

Community
  • 1
  • 1
Ravi Khakhkhar
  • 1,924
  • 1
  • 18
  • 25