0

I am a beginner in mongo db, I have this sample in my database

{
    "_id" : ObjectId("5a95cef390bd8fbf1c699d73"),
    "dr_asin" : "0439394422",
    "dr_description" : "Product that encourages families to learn, explore, and create in new and exciting ways.",
    "dr_price" : 12.96,
    "dr_imUrl" : "http://ecx.images-amazon.com/images/I/51Zx2bIwWcL._SX300_.jpg",
    "dr_related" : {
        "also_bought" : [ 
            "B0002667BI", 
            "B00005JKTY", 
            "B0002667B8"
        ],
        "buy_after_viewing" : [ 
            "B00005JKTY", 
            "B00000DGSW", 
            "B0002667BI"
        ]
    },
    "dr_salesRank" : {
        "Video Games" : 36531
    },
    "dr_categories" : [ 
        [ 
            "Video Games", 
            "Mac", 
            "Games"
        ], 
        [ 
            "Video Games", 
            "PC", 
            "Games"
        ]
    ]
}

I want to find all products that are in the Mac category, I tried all these

db.P15242570_products.find({dr_categories: {$in: ["Mac"]}})
db.P15242570_products.find( { 'dr_categories.Mac': { $exists: true } } )
db.P15242570_products.find({ dr_categories: "Mac" }
db.P15242570_products.find({ dr_categories : { $all : ['Mac'] }});

but nothing is working ? any ideas ?

Jankapunkt
  • 8,128
  • 4
  • 30
  • 59
Doaa Radwan
  • 67
  • 1
  • 9

1 Answers1

2

This worked for me

db.15242570_products.find({"dr_categories":{$elemMatch:{$elemMatch:{$in:["PC"]}}});
Mohit Mutha
  • 2,921
  • 14
  • 25