I have a problem with foreign relations

391 views
Skip to first unread message

Farman Ali

unread,
Apr 19, 2021, 1:53:50 AM4/19/21
to Mongoose Node.JS ODM
I have some problem with foreign relations.

This is the service
  public getCstateByCountry = async (country_id: string): Promise<ICState> => { const data = await Cstate.find({ country: Mongoose.Types.ObjectId(country_id) }); return data; };

And this is the model
const cstateSchema = new Schema( { name: { type: String, unique: true, }, country: { type: Mongoose.Schema.Types.ObjectId, ref: 'Country' } }, { timestamps: true } );

I am getting this error
Type 'ObjectId' is not assignable to type 'Condition<ObjectId>'. Type 'ObjectId' has no properties in common with type 'QuerySelector<ObjectId>'.

Farman Ali

unread,
Apr 19, 2021, 1:54:46 AM4/19/21
to Mongoose Node.JS ODM
This is the question I posted on stackoverflow. If you want more information, do let me know.
https://stackoverflow.com/questions/67152782/one-to-many-relation-objectid-not-working-in-mongoose-mongodb-in-express-typescr

Farman Ali

unread,
Apr 19, 2021, 2:24:17 AM4/19/21
to Mongoose Node.JS ODM
I have updated the question a little bit. Changes type ICstates to any.

Farman Ali

unread,
Apr 19, 2021, 3:11:18 AM4/19/21
to Mongoose Node.JS ODM
Reply all
Reply to author
Forward
0 new messages