Using the 3 documents as an example:
{ _id: '/players/b/berrijo01.shtml',
url: '/players/b/berrijo01.shtml',
name: 'Jose Berrios',
image: 'https://www.baseball-reference.com/req/202108020/images/headshots/d/d94db113_mlbam.jpg',
teams:
[ { name: 'MIN', years: [ 2016, 2017, 2018, 2019, 2020, 2021 ] },
{ name: 'TOR', years: [ 2021 ] } ] }
{ _id: '/players/c/cruzne02.shtml',
url: '/players/c/cruzne02.shtml',
name: 'Nelson Cruz',
image: 'https://www.baseball-reference.com/req/202108020/images/headshots/f/fea2f131_mlbam.jpg',
teams:
[ { name: 'MIL', years: [ 2005 ] },
{ name: 'TEX',
years: [ 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 ] },
{ name: 'BAL', years: [ 2014 ] },
{ name: 'SEA', years: [ 2015, 2016, 2017, 2018 ] },
{ name: 'MIN', years: [ 2019, 2020, 2021 ] },
{ name: 'TBR', years: [ 2021 ] } ] }
{ _id: '/players/m/mauerjo01.shtml',
url: '/players/m/mauerjo01.shtml',
name: 'Joe Mauer',
image: 'https://www.baseball-reference.com/req/202108020/images/headshots/4/43c69595_mlbam.jpg',
teams:
[ { name: 'MIN',
years:
[ 2004, 2005, 2006, 2007,
2008, 2009, 2010, 2011,
2012, 2013, 2014, 2015,
2016, 2017, 2018 ] } ]
}
I want to get any document that has the specified year within the teams array inside the years value.
So for example if I query 2021 I would get the first and second documents. If I query for 2006 I get the second and third documents. I'm not sure how to go about this query as I'm fairly new to mongo.