2017-10-24 10 views
0

を使用してアレイの内部JSONを取得し、このカーソルを使用したモンゴカーソル

{ 

    "_id" : ObjectId("5772932ce4b0be6213704c81"), 
    "employerId" : "57728cd7e4b0be6213704b17", 
    "jobSeekerId" : "5706426ae4b0c7ea74fda18b", 
    "readByJobSeeker" : true, 
    "readByJobEmployer" : true, 
    "interestChat" : [ 
     { 
      "userChat" : "is this job avaliable ", 
      "lastChatRole" : "JOBSEEKER", 
      "lastChatTime" : ISODate("2017-08-10T15:20:25.017Z"), 
      "jobSeekerAcknowledgeFlag" : true, 
      "connectionCounterIncreamented" : false 
     } 
    ], 
    "createdDate" : ISODate("2016-06-28T15:09:32.564Z"), 
    "lastModifiedDate" : ISODate("2017-08-10T15:31:12.564Z"), 
    "version" : NumberLong(20), 
    "active" : true 
} 

問題は、クエリ

db.interest.find({"interestChat":{$exists:true}}).forEach(function(myChat){print ("interest :: "+ myChat.interestChat); }).pretty() 

ないことを利用しているよう
ドキュメントが見え配列であるインナーJSONの値を取得する必要があります関心:: [オブジェクトBSON] インナーjsonの値を取得する必要があります

+0

また 'List'です。これを繰り返す。myChat.interestChat.forEach(... ' –

答えて

0

関数printは、json/bsonオブジェクトを持ち出すことを意図していません。

代わりにprintjsonを試してください。

db.interest.find({"interestChat":{$exists:true}}) 
    .forEach(function(myChat){ 
     printjson({"interest": myChat.interestChat}); 
    }) 

か、単にprintjson(myChat.interestChat);

関連する問題