Q:

MongoDB find in array

I have a mongodb JSON array and I am having issues locating categories, eg.
{ name:"hoyts"}

I have tried {categories.name:"hoyts"} and a few others but nothing seems to work.
This is my JSON:
   {
   "_id": ObjectId("4f67da1538fc5d7347000000"),
   "categories": {
     "id": 1,
     "name": "hoyts",
     "product-logo": "http: \/\/www.incard.com.au\/newsite\/template\/images\/movieticket\/4cinemas\/hoytstop.png",
     "products"▼: {
       "0": {
         "barcode": "25001",
         "name": "GoldClass",
         "Price": "12.00",
         "CashBack": "2.00" 
      },
       "1": {
         "barcode": "25002",
         "name": "Weekday",
         "Price": "12.00",
         "CashBack": "2.00" 
      },
       "2": {
         "barcode": "25003",
         "name": "Weekend",
         "Price": "24.00",
         "CashBack": "4.00" 
      } 
    } 
  },
   "store_name": "movies",
   "1": {
     "id": 2,
     "name": "village",
     "logo": "village.png",
     "products": {
       "0": {
         "barcode": "26001",
         "name": "GoldClass",
         "Price": "12.00",
         "CashBack": "2.00" 
      },
       "1": {
         "barcode": "26002",
         "name": "Weekday",
         "Price": "12.00",
         "CashBack": "2.00" 
      },
       "2": {
         "barcode": "26003",
         "name": "Weekend",
         "Price": "24.00",
         "CashBack": "4.00" 
      } 
    } 
  } 
}

A:

In the JSON you posted categories is not an array, but object. If we assume that you have categories as array (inside []), you should use {"categories.name":"hoyts"} (with quotes for categories.name) for your criteria. The same thing will work if "categories" is not an array, but object (but I think that you wanted to have more categories, since name of the "property" is plural.

