Finding a specific value in a specific position of an array with MongoDB -


this question has answer here:

i new mongodb , trying figure out how can query collection document contains specific value in specific array position. have general idea getting syntax errors when try use $position know i'm off track here despite best effort mongo docs.

as example document trying do, i'll use recipes database collection:

{   "_id": objectid("1234"),   "recipename": "super tasty cilantro lime chicken",   "ingredients": ["chicken breast", "cilantro", "lime"] }, {   "_id": objectid("4321"),   "recipename": "radical cilantro dip",   "ingredients": ["cilantro", "lime", "sour cream"] } 

what best method finding document(s) contains cilantro in 2nd position of ingredients array instead of documents containing cilantro in position?

credit @ali dehghani answer!

try db.collectionname.find({"ingredients.1": "cilantro"}) – ali dehghani