I need to perform a query on a MongoDB database using mongoose to select documents based on the value of properties contained in subdocuments. These are my schemas:
type Map{
id: ID
date: String!
parcels: [Parcel!]!
}
type Parcel {
id: Int
name: String!
x: Int!
y: Int!
}
I'd like to find a parcel by coordinates at a given date, so I tried these queries but I always get null:
Map.find({date: "2022-06-15", parcels:{x: 10, y:20}})
Map.find({date: "2022-06-15", "parcels.x": 10, "parcels.y":20})
Is there any way to avoid retrieving all parcels and then selecting the one I'm looking for?