2017-10-27 7 views
0

에 단어와 일치하는 Object의 배열, 나는 항목라는 데이터베이스에갈릴레오라는 MongoDB의 컬렉션 JSON 형식으로 결과를 수출했다.
는 지금은가 (이름이 제목 필드에있다), 특히 내가 "Astrolabio"을 찾고, 내가 포함 된 모든 개체를 검색 할 수 원하는 이름으로 찾기 항목을 컬렉션에 조회 할 제목 필드에 단어 "Astrolabio"(예 : "Astrolabio", "Astrolabio 피아노"등이 ...). 나에게 관심 객체는 @graph 배열에 포함되어 있습니다.
나는
쿼리 예나를 사용하여 거대한 온톨로지에 쿼리를 실행 한 후 문자열 필드

db.items.find({"@graph":{$elemMatch:{"title":{$regex: /Astrolabio$/}}}}) 

을 시도했지만 너무 검색 한 단어를 포함하지 않는 객체를 많이 반환합니다. 나는 나의 시도는, 그것은 요청과 일치하는 첫 번째 개체를 반환 후에 만 ​​발견으로

나는 또한

db.items.find({},{"@graph":{$elemMatch:{"title":{$regex: /Astrolabio$/}}}}) 

시도했지만.
그래서 내가하려는 일에 대한 올바른 질문은 무엇입니까? 돕는을 제공하기 위해
, 여기에 문서의 작은 조각이

{ 
"_id" : ObjectId("59e07632b5d295462b330c4c"), 
"@graph" : [ 
    { 
     "@id" : "http://minerva.atcult.it/rdf/000000016001", 
     "@type" : [ 
      "bibo:Book", 
      "bibo:MultiVolumeBook" 
     ], 
     "P1053" : [ 
      "1 astrolabe", 
      "1 astrolabio" 
     ], 
     "abstract" : [ 
      "This astrolabe presently comprises two tympanums, for latitudes 30° and 33°, the other for latitudes 36° and 42° (corresponding to the regions between Persia and the Black Sea). There is an alidade, a rule, and a rete. The back carries a double shadow square and the zodiacal calendar. The instrument comes with a tooled black leather case (cover missing) containing a sixteenth-century manuscript note stating that the astrolabe was brought from Spain and dates from 1252. The astronomical data inscribed on the astrolabe suggest it may have been built before 1000. According to tradition, the instrument dates from the period of Charlemagne (9th C.). A very similar Arab astrolabe is documented in a drawing by Antonio da Sangallo il Giovane [the Younger] (c.  1520?) at the Gabinetto dei Disegni e delle Stampe (Department of Drawings and Prints) of the Uffizi. Provenance: Medici collections", 
      "Questo astrolabio contiene attualmente due timpani, uno per le latitudini 30° e 33°, e l'altro 36° e 42° (corrispondenti alle regioni comprese tra la Persia e il Mar Nero). È completo di alidada, di regolo e di rete. Nel dorso presenta un doppio quadrato delle ombre e il calendario zodiacale. Lo strumento, proveniente dalle collezioni medicee, è completo di custodia di pelle nera lavorata (coperchio mancante) che porta all'interno una nota manoscritta del XVI secolo nella quale si ricorda che l'astrolabio fu portato dalla Spagna e che risale al 1252. I dati astronomici riportati sullo strumento suggeriscono di anticiparne la costruzione a prima del 1000. Secondo la tradizione si tratterebbe di uno strumento del tempo di Carlo Magno (IX secolo). Un astrolabio arabo molto simile a questo è documentato in un disegno di Antonio da Sangallo il Giovane (c. 1520?) conservato presso il Gabinetto dei Disegni e delle Stampe degli Uffizi. Proviene dalle collezioni medicee" 
     ], 
     "contributor" : "http://minerva.atcult.it/rdf/ed494c3a-2ba6-3464-b34a-a57e4f70c5e0", 
     "creator" : [ 
      "http://minerva.atcult.it/rdf/d481cbac-209b-3741-bba4-906590d805b3", 
      "http://minerva.atcult.it/rdf/36e6efa2-6c8f-350e-ae37-479dade48850", 
      "http://minerva.atcult.it/rdf/47734211-2637-3895-a690-4f33412931ec" 
     ], 
     "identifier" : "000000016001", 
     "issued" : "sec. X", 
     "publisher" : "http://minerva.atcult.it/rdf/90310a84-1133-3356-bb3b-647ae1a7d14d", 
     "title" : "Astrolabio piano", 
     "numPages" : [ 
      "1 astrolabio", 
      "1 astrolabe" 
     ], 
     "placeOfPublication" : "Fattura araba", 
     "label" : "Astrolabio piano" 
    }, 
    { 
     "@id" : "http://minerva.atcult.it/rdf/000000016002", 
     "@type" : [ 
      "bibo:MultiVolumeBook", 
      "bibo:Book" 
     ], 
     "P1053" : [ 
      "1 astrolabe", 
      "1 astrolabio" 
     ], 
     "abstract" : [ 
      "Questo piccolo astrolabio contiene quattro timpani per le latitudini 24° e 30°, 31° e 35°, 32° e 36° (corrispondenti alla Persia) e per le latitudini 0° (cioè il circolo dell'equatore) e 66°. È completo di alidada e di rete. Il dorso della madre presenta il calendario lunare, secondo l'uso islamico, un quadrato delle ombre e un quadrante. Lo strumento reca la data 496 dell'Egira (1102-1103 dell'età Cristiana) ed è firmato dal suo artefice, Muhammad 'Ibn Abi'l Qasim 'Ibn Bakran, del quale non si hanno notizie. Fu donato al Museo di Storia della Scienza dal Principe fiorentino Tommaso Corsini", 
      "This small astrolabe carries four tympanums for latitudes 24°/30°, 31°/35°, and 32°/36° (corresponding to Persia), and for latitude 0° (i. e. , the circle of the equator) and 66°. There is an alidade and a rete. The back of the mater displays a lunar calendar, in accordance with Islamic use, a shadow square, and a quadrant. The instrument is dated 496 of the Hegira (1102-1103 of the Christian era) and is signed by its maker, Muhammad 'Ibn Abi'l Qasim 'Ibn Bakran, on whom we have no information. Donated to the Museo di Storia della Scienza by the Florentine Prince Tommaso Corsini" 
     ], 
     "creator" : [ 
      "http://minerva.atcult.it/rdf/c5738e64-fb77-354a-8fc8-47164105b5f7", 
      "http://minerva.atcult.it/rdf/3fa79916-cb7f-3574-a3fb-589ca42ebf17" 
     ], 
     "identifier" : "000000016002", 
     "issued" : "1102-1103", 
     "publisher" : "http://minerva.atcult.it/rdf/90310a84-1133-3356-bb3b-647ae1a7d14d", 
     "title" : "Astrolabio piano", 
     "numPages" : [ 
      "1 astrolabio", 
      "1 astrolabe" 
     ], 
     "placeOfPublication" : "Fattura araba", 
     "label" : "Astrolabio piano" 
    }, 

답변

1

당신이 결과에 가질 필요가있는 경우 제목이 단어가 Astrolabio를 포함하는 경우 (쿼리와 일치하는 @graph 배열의 요소), 다음 통합 프레임 워크 쿼리가 도달 할 수 있습니다 : 마지막 단어가 문장이기 때문에

db.items.aggregate([  
    {$match: {"@graph.title": /Astrolabio/}},  
    {$unwind: "[email protected]"},  
    {$match: {"@graph.title": /Astrolabio/} }, 
    {$group: {"_id": "$_id", "@graph": {"$push": "[email protected]" } }} 
]); 

정규식 {$regex: /Astrolabio$/}은 'Astrolabio을'이 제목 만 문서를 반환합니다 ("Astrolabio 피아노"는 포함되지 않습니다 '피아노'가 마지막 단어입니다.)

+0

답장을 보내 주셔서 감사합니다. 제안한 두 가지 쿼리를 모두 시도했지만 불행히도 내가 원하는 결과를 제공하지 못했습니다. 첫 번째는 전체 문서를 계속 보여 주며, 배열의 모든 요소를 ​​반환하는 db.items.find ({}, { "@ graph.title":/Astrolabio /}) 변형도 시도했습니다. ** title ** 필드. 대신 두 번째 쿼리는 결과를 제공하지 않습니다. – HJuls2

+0

@ HJuls2, 위에서 설명한 문서 (''_id ': ObjectId ("59e07632b5d295462b330c4c")')로 원하는 출력을 작성하십시오. 어쩌면 내가 너의 질문을 오해 할 수도있다. 출력에 제목 필드 만 필요합니까 (또는 _id 필드 포함)? –

+0

** 모든 ** ** ** 모든 필드 **는 쿼리와 일치하는 * @ graph * 배열의 요소가 필요합니다. Istead I ** 요소에 일치 항목이있는 경우 첫 번째 요소 만 일치하거나 다른 한편으로는 배열의 모든 요소가 필요하지 않습니다. 예를 들어, 배열에 위의 두 가지 요소가 있다고 가정하고 자신의 필드와 * title * 필드 "Telescopio"가있는 다른 요소를 추가하면 * Astrolabio * ** 및 ** * Astrolabio piano의 모든 필드가 결과에 포함되어야합니다. *, ** Telescopio *의 필드는 아닙니다 **. – HJuls2