表示res.json()丢失数据
我试图使用快递发送数据,但由于某种原因它丢失了部分数据。
function(err, data) { if (err) console.log(err); console.log(data); res.json(data); }
variables数据看起来像(简化):
{field1: 'value1', field2: 'value2', field3: {subfield: 'subvalue'}}
但在浏览器中我收到:
{field1: 'value1', field2: 'value2', field3: null }
我做错了什么或缺less什么?
更新:
完整的代码
UserReadingData.find({ UserId: { "$exists": true, "$eq": user._id }, InFuture: false, Stopped: false }) .populate('SeriesId', 'SeriesName') .exec(function(err, data) { if (err) console.log(err); console.log(data); res.json(data); });
浏览器中的SeriesId为空。
更新2:
console.log(数据)的结果:
{ Issues: [ 575efe1c3d6d04662a2cd1c4 575efe1c3d6d04662a2cd1d3 ], Stopped: false, InFuture: false, __v: 0, SeriesId: { SeriesName: 'Test name', _id: 575efe1b3d6d04662a2cd188 }, UserId: 561c080aa849427a8699cafd, _id: 575f0981ddac1c802d9d1536 }
更新3:
我的模式
var seriesSchema = mongoose.Schema({ Meta: metaInformationSchema, SeriesName: String, Description: String, Creators: [creatorsSchema], Featured: [featuredSchema], PublisherName: String, IsStoryArc: Boolean, Issues: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Issue' }]}, { collection: 'library'}); var userReadingDataSchema = mongoose.Schema({ UserId: { type: mongoose.Schema.Types.ObjectId, ref: 'User' }, SeriesId: { type: mongoose.Schema.Types.ObjectId, ref: 'Series' }, Issues: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Issue' }], InFuture: Boolean, Stopped: Boolean}, {collection: 'readingdata'});
我来自sql,这是我第一次使用mongo。
我不知道什么是错的真正的原因,但我从收集readingdata
删除了一切,并填补了一些新的数据。 之后它res.json
正常工作。