I have two models:
Building Schema:
@Schema({
collection: 'building',
})
export class Building {
@Prop({ type: Types.ObjectId, required: true })
playerId: Types.ObjectId;
...
}
Town schema:
@Schema({ timestamps: true })
export class Town {
@Prop({ type: Types.ObjectId, required: true })
playerId: Types.ObjectId;
...
}
When I'm querying with the buildingModel I'm not required to use new ObjectID
const building = await this.buildingModel.findOne({ playerId });
But when I'm querying with the townModel I am required to use new ObjectId(..)
const owner = await this.townModel.findOne({ playerId: new ObjectId(playerId) });
Without new ObjectId on the townModel, my queries fail. I really want to know the reason