【发布时间】:2018-06-01 08:13:00
【问题描述】:
我有使用外键与国家相关的国家。在获取国家时,我无法获得相关国家,但得到一个奇怪的结果。以下是我的模型
国家模式 var 猫鼬 = 要求('猫鼬'); var Schema=mongoose.Schema
var CountrySchema =Schema(
{
name:{type:String,required:true},
code :{type:String},
status: { type: Boolean, default:true }
}
)
module.exports = mongoose.model('Country', CountrySchema
)
状态模型
var mongoose = require('mongoose');
var Schema=mongoose.Schema
var Country =require('../../models/location/country');
var StateSchema=Schema(
{
name:{type:String,required:true},
code :{type:String},
status: { type: Boolean, default:true },
country: { type: Schema.ObjectId, ref: 'Country', required: true },
country:[Country.schema]
}
)
module.exports = mongoose.model('State', StateSchema)
我的回复如下
{
"data": {
"5a36f32fc6ac751b711e9b19": {
"name": "Kerala",
"code": "KL",
"_id": "5a36f32fc6ac751b711e9b19",
"__v": 0,
"country": [
{
"_bsontype": "ObjectID",
"id": {
"type": "Buffer",
"data": [
90,
47,
16,
175,
152,
157,
109,
20,
5,
111,
70,
142
]
},
"status": true
}
],
"status": true
}
}
}
为什么我获取国家/地区的这种类型数据而不是获取正确的数据
【问题讨论】:
标签: node.js mongodb express mongoose