{
"token": "ayuAaCahms6qTD8LJrL6e/IaUBZSzAfIg7pOu5zKbkw=",
"photo": [{"height": 500, "preview": "xxxx ", "url": "http://xyz.jpg", "width": 375}, {"height": 500, "preview": "skjdfbsdjvns;abc ", "url": "http://abc.jpg", "width": 375}],
"user_id": "5fce2865cf6b771054133984",
"mimetype" : "images/jpeg",
"device_platform" : "ios"
}
How do store this object into multiple document into databases since photo has array. If photo has more than 1 data it should store in mulitple document i.e
{
"_id" : ObjectId("5fce2865cf6b771054133911")
"token": "ayuAaCahms6qTD8LJrL6e/IaUBZSzAfIg7pOu5zKbkw=",
"photo": {"height": 500, "preview": "xxxx ", "url": "http://xyz.jpg", "width": 375},
"user_id": "5fce2865cf6b771054133984",
"mimetype" : "images/jpeg",
"device_platform" : "ios"
}
{
"_id" : ObjectId("5fce2865cf6b771054133998")
"token": "ayuAaCahms6qTD8LJrL6e/IaUBZSzAfIg7pOu5zKbkw=",
"photo": {"height": 500, "preview": "skjdfbsdjvns;abc ", "url": "http://abc.jpg", "width": 375},
"user_id": "5fce2865cf6b771054133984",
"mimetype" : "images/jpeg",
"device_platform" : "ios"
}
I tried that way but I am that is not going to work
if(photo !== undefined && photo.length > 0) {
let value = { ...req.body }
for(let key in { ...value }) {
let userStatus = []
if( value.hasOwnProperty(key) ) {
let record = await new User({
user_id: value[key].user_id,
photo: value[key].photo,
mimetype: value[key].mimetype,
device_platform: value[key].device_platform,
}).save()
userStatus.push(record)
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…