繁体   English   中英

带有数组的node.js api

[英]node.js api with array's

我对node.js和javascript很陌生。 我已经建立好了,并且使用了api,但突然之间数据模型发生了变化,现在我有点迷失了。

这是我的代码:

var mongoose = require('mongoose');


//create schema
var MedicSchema = new mongoose.Schema({
  nombre:{
      type: String,
      required: true
  },
  especialidad:{
    type: String,
    required: true
  },
  ranking:{
    type: Number,
  },

  direccion: [{
        direccion: {type: String, required: true},
        telefono: {type: String},
        horario:{type: String}
        }],

    foto:{
    type: String,
}
});

MedicSchema.find({})
.populate('direccion')
.exec(function (err, medic) {
    console.log(medic.direccion); // This should have your information now
});

//export model
module.exports = MedicSchema;

我能够将数据发送到direccion数组...但是当我调用api时; 我得到这个:

{
    "_id": "557839b36bcdd00e09173e36",
    "nombre": "Sra. Hong",
    "especialidad": "general",
    "__v": 0,
    "direccion": [
        {
            "_id": "55a44392b2e774572b957a8e"
        },
        {
            "_id": "55a44392b2e774572b957a8d"
        }
    ]
}

我找不到一种方法来调用数组的详细信息。

编辑:我将其发布在bitbucket https://bitbucket.org/weput/api-server

您需要填充“ direccion”数组。 例如:

MedicSchema.find({})
.populate('direccion')
.exec(function (err, medic) {
    console.log(medic.direccion); // This should have your information now
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM