我正在尝试使用 express 发送数据,但由于某种原因它丢失了部分数据。
function(err, data) {
if (err) console.log(err);
console.log(data);
res.json(data);
}
变量数据看起来像(简化的):
{field1: 'value1', field2: 'value2', field3: {subfield: 'subvalue'}}
但是在浏览器中我收到:
{field1: '值1', field2: '值2', field3: null }
我是不是做错了什么或者遗漏了什么?
更新:
完整代码
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(data)结果:
{ 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
正常工作。
关于node.js - 表达 res.json() 丢失数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37798446/