i'm learning MongoDB for a few weeks now and i have still no idea how to query nested documents in my project. I read the MongoDB-docs and googled a lot, but i found no good explanations or tutorials for my problem. Maybe you can help me!
I have three Collections which are referencing each other:
const shipmentSchema = new mongoose.Schema({
item: {
type: String,
required: true,
},
cityId: {
type: mongoose.Schema.Types.ObjectId,
ref: "City",
},
});
const citiesShcema = new mongoose.Schema({
cityName: {
type: String,
required: true,
},
countryId: {
type: mongoose.Schema.Types.ObjectId,
ref: "Countries",
required: true,
},
});
const countriesSchema = new mongoose.Schema({
countryName: {
type: String,
required: true,
},
});
const Shipment_new = mongoose.model("Shipment_new", shipmentSchema);
const Cities = mongoose.model("City", citiesShcema);
const Country = mongoose.model("Countries", countriesSchema);
So, guys I was wondering if there's way to query shipments from a country... I mean I want to get all shipments with in a country. So, I tried to work it solved with my own and this what I tried:
const filterShipment = {
cityId: {
countryId: "5f6bbe558b094c14103a7776",
},
};
const shimpents = await Shipment_new.find(filterShipment);
But this didn't do the work so guys, you may wanna help me out here.... I just want get the shipments of a specific countray? THANKS IN ADVANCE