-1
Product_Detail.findOne({"detail.id_product": req.params.id}, function(err, detail){
            console.log(detail)
            console.log(detail.detail)
            console.log(detail.images)               
        })

This is returned from server:

{ _id: 5ee98e2be3234843a4480dee,
  detail:
   { id_product: 'dt-abc',
     monitor: 'afgh',
     camera_truoc: 'asdfg',
     camera_sau: 'dfghj',
     ram: '4 GB',
     memory: '128 GB',
     cpu: 'Kirin 710F 8 nhân',
     gpu: 'dfdsf',
     pin: 'fdq',
     operation: 'Android 9.0 (Pie)',
     sim: '2 SIM Nano (SIM 2 chung khe thẻ nhớ), Hỗ trợ 4G',
     micro_sd: 'MicroSD, hỗ trợ tối đa 512 GB',
     origin: '123456' },
  images:
   [ { fieldname: 'file_multipile',
       originalname: '1.png',
       encoding: '7bit',
       mimetype: 'image/png',
       destination: './public/images/products/',
       filename: '15923645875301.png',
       path: 'public\\images\\products\\15923645875301.png',
       size: 856150 },
     { fieldname: 'file_multipile',
       originalname: '2.png',
       encoding: '7bit',
       mimetype: 'image/png',
       destination: './public/images/products/',
       filename: '15923645876482.png',
       path: 'public\\images\\products\\15923645876482.png',
       size: 213809 },
     { fieldname: 'file_multipile',
       originalname: '3.png',
       encoding: '7bit',
       mimetype: 'image/png',
       destination: './public/images/products/',
       filename: '15923645876613.png',
       path: 'public\\images\\products\\15923645876613.png',
       size: 171848 },
     { fieldname: 'file_multipile',
       originalname: '4.png',
       encoding: '7bit',
       mimetype: 'image/png',
       destination: './public/images/products/',
       filename: '15923645876674.png',
       path: 'public\\images\\products\\15923645876674.png',
       size: 836256 } ] }
undefined
undefined

Why console.log(detail.detail) and console.log(detail.images) return undefined. ssssssssssssssssssssssssssssssssssssssssssssssssssThankssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss

Trí Phan
  • 11
  • 3
  • Can you try logging `typeof detail` as your first console log. If its string then you will have to JSON.parse it. – surajs21 Jun 17 '20 at 04:24
  • 2
    Looks like that isn't valid JSON. – Flaom Jun 17 '20 at 04:26
  • Assuming this is mongoose, could you post the model definition for `Product_Detail`? – ATOMP Jun 17 '20 at 04:26
  • It return object – Trí Phan Jun 17 '20 at 04:26
  • 1
    As @atomp suggested, if its mongoose then you will not be able to get a property easily. Try doing `detail = detail.toObject()` as first thing. – surajs21 Jun 17 '20 at 04:32
  • @surajs21 thank you very much, i just add detail = detail.toObject() and it work – Trí Phan Jun 17 '20 at 04:34
  • You may want to try one of these to improve your workflow instead of writing `toObject()` everywhere https://stackoverflow.com/questions/7503450/how-do-you-turn-a-mongoose-document-into-a-plain-object – ATOMP Jun 17 '20 at 04:40

1 Answers1

1

Assuming it to be a mongoose code, you can not get property easily. Can you try this

Product_Detail.findOne({"detail.id_product": req.params.id}, function(err, detail){
    detail = detail.toObject(); // this

    console.log(detail)
    console.log(detail.detail)
    console.log(detail.images)              
})

surajs21
  • 128
  • 1
  • 8