I am new to mongodb and am trying to make this type of entry:
{
"resources": [
{
"amount": 1,
"resource": {
"_id": "61be82b9549b4ede0c8df07e"
}
}
]
}
Here is my schema code:
const schema = new Schema({
resources: [
{
amount: {
type: Number,
required: true,
},
resource: {
_id: {
type: Schema.Types.ObjectId,
ref: "Resource"
}
}
}
]
});
here is the json code i send
{
"resources": [
{
"amount": 1,
"resource": "61be82b9549b4ede0c8df07e"
}
]
}
After processing the request, the following entry is created
{
"resources": [
{
"amount": 1,
"resource": "61be82b9549b4ede0c8df07e",
"_id": "61ebebf0e20286eee987bdc3"
}
],
"_id": "61ebebf0e20286eee987bdc2",
"__v": 0
}
Id for the resource was created correctly, but I can’t figure out where the resources._id key came from? Where did I make a mistake?