I have a schema called subcategory
:
const subCategorySchema = new mongoose.Schema({
name: {
type: String,
required: true
},
description: {
type: String,
required: false
},
category: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Category',
required: true
},
image: {
type: String,
required: false
}
})
However when executing this: const subCategoryRecord = await this.subCategoryModel.findById("idAsString")
i get null
I read about other questions like this
(says here that i should send new ObjectId('id')
instead of string
)
but i have another schema called category
, and while doing findById
by sending a string i DO get a result, what is the difference?
that's the category schema:
const categorySchema = new mongoose.Schema({
name: {
type: String,
required: true
},
description: {
type: String,
required: false
},
image: {
type: String,
required: false
}
})
this WORKS: const category = await this.categoryModel.findById('categoryIdAsString')