2016-06-13 104 views
2

我試圖使用快遞發送數據,但由於某種原因它丟失了部分數據。Express res.json()丟失數據

function(err, data) { 
    if (err) console.log(err); 

    console.log(data); 
    res.json(data); 
} 

可變數據看起來像(簡體):

{field1: 'value1', field2: 'value2', field3: {subfield: 'subvalue'}}

但在瀏覽器中我收到:

{field1: 'value1', field2: 'value2', 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在瀏覽器爲null。

更新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的時候。

+0

數據究竟是什麼?它來自哪裏? – robertklep

+0

我使用完整代碼更新了一個問題 – emwsc

+0

user.id'確實存在於數據庫中嗎? – peteb

回答

0

我不知道什麼是錯的真正原因,但我從集合readingdata刪除了一切,並填充了一些新的數據。之後它res.json正常工作。