猫鼬json输出错误

时间:2018-09-03 17:40:45

标签: json mongoose

我从mongodb获得了这些数据

{ _id: 5b339ddd9e1d0794611234,
  staff:
   [ { staff_id: [Array] },
     { staff_id: [Object] } ] }

我把它串起来产生

{"_id":"5b339ddd9e1d0794611234","staff":[
    {"staff_id":[{"details":{"first_name":"Smith","other_names":"","last_name":"James","title":"mr"},
    "_id":"5b88efedc4bb91221005c71b","contact":[{"_id":"5b88efedc4bb912210345838","address":"No 15, blake Str " }],
    "qualification":[{"_id":"5b88efedc4bb91221005c71e","certificate":"Bachelor's of Science","qualification_date":"2013-08-08"}],"__v":0}]},

    {"staff_id":{"details":{"first_name":"Emily","other_names":"Diana","last_name":"Kinus","title":"ms"},
    "_id":"5b8ae7324a9a0515d09b0877","contact":[{"_id":"5b8ae7324a9a0515d09b0879","address":"No 15, greenway Str"}],
    "qualification":[{"_id":"5b8ae7324a9a0515d09b087a","certificate":"Bachelor's of Science","qualification_date":"2016-09-01"},
    {"_id":"5b8ae7324a9a0515d09b087b","certificate":"M.Sc","qualification_date":"2016-09-01"}],"__v":0}}]}

第一个文档是数组,而第二个文档则不是。但是我在提取其中的任何数据时遇到了问题。我所做的一些事情是。

var str = JSON.stringify(data)

1. str[0]['staff']['staff_id'][0]['details']['first_name']

2. data[0]['staff']['staff_id'][0]['details']

3. str['staff']['staff_id'][0]['details']

4. str._id

5. str['_id']

以上所有内容均未定义

0 个答案:

没有答案