2014-10-08 4 views
2

내 JSON 데이터가 이것이다, (이 나는 몽고 DB에 저장하는 것)mongo DB에서 json 데이터의 내부 값을 가져 오는 방법이 있습니까?

/* 0 */ 
{ 
    "_id" : "e9925559-4830-476f-8d6a-789ade4ec51c", 
    "account_user_id" : "sahaal", 
    "account_number" : "23423", 
    "Job Profile" : { 
     "externalid" : "250250ICM", 
     "bgcpackagetype" : [ 
      { 
       "id" : "C19902", 
       "value" : "1800 - Happy Path Background Check", 
       "formattedvalue" : "1800 - Happy Path Background Check" 
      }, 
      { 
       "id" : "C19900", 
       "value" : "2112 - Esteem Validation Package", 
       "formattedvalue" : "2112 - Esteem Validation Package" 
      } 
     ], 
     "links" : [ 
      { 
       "title" : "The current profile being viewed.", 
       "rel" : "self", 
       "url" : "https://api.icims.com/customers/2187/jobs/2015" 
      } 
     ], 
     "jobid" : "2013-2015" 
    }, 
    "request" : { 
     "newStatus" : "9782", 
     "oldStatus" : "1752", 
     "customerId" : "1234", 
     "jobId" : "1242", 
     "userId" : "3", 
     "personId" : "1364", 
     "links" : [ 
      { 
       "title" : "Applicant Workflow", 
       "rel" : "applicantWorkflow", 
       "url" : "https://api.icims.com/customers/1234/applicantworkflows/2203" 
      }, 
      { 
       "title" : "Job Profile", 
       "rel" : "job", 
       "url" : "https://api.icims.com/customers/2187/jobs/2015" 
      }, 
      { 
       "title" : "Person Profile", 
       "rel" : "person", 
       "url" : "https://api.icims.com/customers/2187/people/7260" 
      }, 
      { 
       "title" : "Posting User", 
       "rel" : "user", 
       "url" : "https://api.icims.com/customers/2187/people/7425" 
      } 
     ] 
    }, 
    "Candidate Profile" : { 
     "workexperience" : [ 
      { 
       "workdescription" : "Investigated the effects on body weight and bone growth of replacement injections of thyroid hormone and drugs that inhibit thyroid hormone production * Performed IM injections in chickens * Ran 80 blood samples through gas chromatograph to check T1 levels * Prepared bone growth media for 8 sets of experiments", 
       "entry" : 47964, 
       "workstartdate" : "2011-01-01", 
       "workenddate" : "2011-06-01", 
       "worktitle" : "Research Assistant", 
       "workemployer" : "UC Riverside" 
      }, 
      { 
       "workcity" : "Pomona", 
       "workdescription" : "Worked closely with staff performing tasks such as escorting patients, preparing charts, stocking rooms with supplies, running errands, answering phones, and light clerical tasks * Provided patient care by taking vital signs, weighing patients, answering call lights and providing psychosocial support for patients * Learned basics of telemetry", 
       "entry" : 47965, 
       "workstartdate" : "2009-05-01", 
       "workcountry" : { 
        "id" : "D41001", 
        "value" : "United States", 
        "abbrev" : "US" 
       }, 
       "workenddate" : "2011-06-01", 
       "worktitle" : "Intern", 
       "workstate" : { 
        "id" : "D41001008", 
        "value" : "California", 
        "abbrev" : "CA" 
       }, 
       "workemployer" : "Pomona Valley Hospital Medical Center" 
      } 
     ], 
     "licensecertification" : [ 
      { 
       "stateissued" : { 
        "id" : "D41001008", 
        "value" : "United States - California", 
        "formattedvalue" : "United States - California" 
       }, 
       "entry" : 48064, 
       "licensecertstatus" : { 
        "id" : "D37002036001", 
        "value" : "Current", 
        "formattedvalue" : "Current" 
       }, 
       "licensenumber" : "D8257463", 
       "licensetype" : "Drivers License" 
      } 
     ], 
     "email" : "[email protected]", 
     "birthdate" : "1970-01-01", 
     "lastname" : "Landis", 
     "links" : [ 
      { 
       "title" : "The current profile being viewed.", 
       "rel" : "self", 
       "url" : "https://api.icims.com/customers/2187/people/7260" 
      } 
     ], 
     "firstname" : "Job", 
     "addresses" : [ 
      { 
       "addresstype" : { 
        "id" : "D84002", 
        "value" : "Home", 
        "formattedvalue" : "Home" 
       }, 
       "addresscountry" : { 
        "id" : "D41001", 
        "value" : "United States", 
        "abbrev" : "US" 
       }, 
       "addresszip" : "92521", 
       "addressstreet1" : "1234 Street Name", 
       "entry" : 3403, 
       "addressstate" : { 
        "id" : "D41001008", 
        "value" : "California", 
        "abbrev" : "CA" 
       }, 
       "addresscity" : "Riverside" 
      } 
     ], 
     "education" : [ 
      { 
       "degree" : { 
        "id" : "C19850", 
        "value" : "B.S", 
        "formattedvalue" : "B.S" 
       }, 
       "school" : { 
        "id" : "C19849", 
        "value" : "University of California", 
        "formattedvalue" : "University of California" 
       }, 
       "entry" : 289, 
       "major" : { 
        "id" : "C19852", 
        "value" : "Biological Sciences", 
        "formattedvalue" : "Biological Sciences" 
       } 
      } 
     ], 
     "phones" : [ 
      { 
       "phonetype" : { 
        "id" : "D83002", 
        "value" : "Home", 
        "formattedvalue" : "Home" 
       }, 
       "phonenumber" : "555-555-5555", 
       "entry" : 4823 
      }, 
      { 
       "phonetype" : { 
        "id" : "D83003", 
        "value" : "Fax", 
        "formattedvalue" : "Fax" 
       }, 
       "phonenumber" : "666-555-6666", 
       "entry" : 4829 
      } 
     ] 
    }, 
    "account_password" : "Pass12!$", 
    "Recruiter Profile" : { 
     "email" : "[email protected]", 
     "lastname" : "HiringManager", 
     "links" : [ 
      { 
       "title" : "The current profile being viewed.", 
       "rel" : "self", 
       "url" : "https://api.icims.com/customers/2187/people/7171" 
      } 
     ], 
     "firstname" : "Harry" 
    } 
} 

검색 결과를해야에만 표시

"links" : [ 
       { 
        "title" : "Applicant Workflow", 
        "rel" : "applicantWorkflow", 
        "url" : "https://api.icims.com/customers/1234/applicantworkflows/2203" 
       }, 
       { 
        "title" : "Job Profile", 
        "rel" : "job", 
        "url" : "https://api.icims.com/customers/2187/jobs/2015" 
       }, 
       { 
        "title" : "Person Profile", 
        "rel" : "person", 
        "url" : "https://api.icims.com/customers/2187/people/7260" 
       }, 
       { 
        "title" : "Posting User", 
        "rel" : "user", 
        "url" : "https://api.icims.com/customers/2187/people/7425" 
       } 
      ] 

편집 : -

내 필요하다 , "title"= "Person Profile"중 url이 필요합니다. 그것은 어떤 위치에있을 수있는 것처럼 그래서 나는 당신이 투영되도록 점 표기법에 의해 배열의 하위 문서를 얻을 수 "request.links":1,_id:0

db.collection.find({query},{"request.links":1,_id:0}) 

에 트릭을 할해야 세 번째 URL을

+0

당신이 JSON 문서는 링크 필드를 포함하는 원하거나 당신이 원하는합니까 링크 만 표시 제목과 링크에 대한

  • 둘째 $match 검색 각 배열 요소에 대한 하나의 문서를 만드는 그것도 중괄호를 잃어 버리니? – Trudbert

  • +0

    결과는 적절한 json 형식이어야하므로 중괄호가 필요합니다 – Sahal

    +0

    은 질문에서 편집했습니다 – Trudbert

    답변

    2

    을 말할 수있다.

    당신이 집계가 필요합니다 편집 된 질문의 경우 : 편집 된 질문 후


    db.collection.aggregate([{$match: {Your document query}}, 
              {$unwind: "$request.links"}, 
              {$match: {"request.links.title":"Person Profile"}}, 
              {$project: {_id : 0, link : "$request.links.url"}}]) 
    

    단계별 설명 :

    1. 먼저 $match이 문서 (에서와 같은 발견 찾기)
    2. $unwind
    3. $project
    +0

    질문을 편집했습니다. 제게 그것에 대해서도 답변을 제공해 주시겠습니까? – Sahal

    +0

    "url"만 필요합니다. "https://api.icims.com/customers/2187/people/7260" – Sahal

    +0

    @Sahal 집계에 일부 오타가있을 것입니다. – Trudbert

    관련 문제