I’m exporting data from an API to JSON files and importing them to MongoDB. My problem is that if I have an Object within the document I can’t write data to that Object and I can’t find what is causing the problem. From what I’ve read it’s possible to use Object type in a Schema but I can’t find a working solution, instead I have to completely restructure the JSON file to not include Objects.
Reconfigured everything from scratch multiple times, tried looking for solutions all over the internet but no luck.
This is my Schema
const { Schema } = mongoose;
const phoneSchema = new Schema({
id:{type: String, required:false},
data:{
key:{type: String, required: false},
device_name:{type: String, required: false},
display_size:{type: String, required: false},
display_res:{type: String, required: false},
camera:{type: String, required: false},
video:{type: String, required: false},
ram:{type: String, required: false},
chipset:{type: String, required: false},
battery:{type: String, required: false},
batteryType:{type: String, required: false},
release_date:{type: String, required: false},
body:{type: String, required: false},
os_type:{type: String, required: false},
storage:{type: String, required: false},
comment:{type: String, required: false},
pictures: {type: Array, required: false}
}
});```
When I run the following, only the "id" is inserted and nothing else. What am I missing?
const iphone13p = new Phone ({key:”apple_iphone_13_pro”, os_type:”iOS17″,storage:”512GB”, id:”i13p”});
iphone13p.save();
Oh, and I almost forgot. I tried data.key: , data.os_type: , etc. but it doesn't work.
I'm really new to these things, any help would be appreciated.
Thanks!
csycsa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.