2016-06-13 2 views
2

급행을 사용하여 데이터를 보내려고하지만 어떤 이유로 데이터가 손실됩니다.Express res.json() 데이터 손실

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

을하지만 브라우저에서 나는 나타납니다 :

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

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

변수 데이터 (간체)과 같은

{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에서 와서 처음이야 내가 몽고를 사용할 때.

+0

'데이터'는 정확히 무엇입니까? 이것은 어디서 오는 거니? – robertklep

+0

전체 코드로 질문을 업데이트했습니다 – emwsc

+0

DB에'user.id'가 실제로 있습니까? – peteb

답변

0

나는 진짜 이유가 무엇인지 알지 못합니다. 그러나 나는 컬렉션 readingdata에서 모든 것을 제거하고 새로운 데이터로 채웠습니다. 그 후 res.json 제대로 작동했습니다.