2015-04-06 66 views
1

以下查询返回不包含TextBox2中城市的所有结果。如果城市名称与TextBox2中的值匹配,如何获取json文档。在MongoDB中从json文档中获取错误结果c#

var query2 = collection.Find(Query.Matches("clinical_study.location.facility.address.city", TextBox2.Text)); 

目前MongoDB数据库包含一个包含4个JSON文件的集合。其中一个JSON文档的格式如下。其他人的形式相似。

{ 
    "?xml": { 
    "@version": "1.0", 
    "@encoding": "UTF-8" 
    }, 
    "clinical_study": { 
    "@rank": "381", 
    "#comment": [], 
    "required_header": { 
     "download_date": "ClinicalTrials.gov processed this data on March 18, 2015", 
     "link_text": "Link to the current ClinicalTrials.gov record.", 
     "url": "http://clinicaltrials.gov/show/NCT00001292" 
    }, 
    "id_info": { 
     "org_study_id": "920106", 
     "secondary_id": "92-C-0106", 
     "nct_id": "NCT00001292" 
    }, 
    "brief_title": "Study of Scaling Disorders and Other Inherited Skin Diseases", 
    "official_title": "Clinical and Genetic Studies of the Scaling Disorders and Other Selected Genodermatoses", 
    "sponsors": { 
     "lead_sponsor": { 
     "agency": "National Cancer Institute (NCI)", 
     "agency_class": "NIH" 
     } 
    }, 
    "source": "National Institutes of Health Clinical Center (CC)", 
    "oversight_info": { 
     "authority": "United States: Federal Government" 
    }, 
    "brief_summary": { 
     "textblock": "\r\n  The purpose of this study is to identify the genes responsible for certain scaling disorders\r\n  and other inherited skin diseases and to learn about the medical problems they cause. In\r\n  some cases, these may include problems affecting organs other than the skin, such as the\r\n  eyes, teeth and bones.\r\n\r\n  Patients with inherited skin disorders, including Darier's disease (keratosis follicularis),\r\n  lamellar ichthyosis, epidermolysis bullosa, cystic acne, and others, and their relatives may\r\n  be eligible for this study. Patients will have a medical history, physical examination with\r\n  particular emphasis on the skin, and routine blood tests. Additional procedures for\r\n  patients and unaffected relatives may include:\r\n\r\n  1. Blood sample collection\r\n\r\n  2. Dental exam with X-ray of the jaw\r\n\r\n  3. Eye examination\r\n\r\n  4. X-rays of the skull, ribs, chest, hands, feet, spine, arms, or legs\r\n\r\n  5. Bone density scan\r\n\r\n  6. Photographs of the skin\r\n\r\n  7. Skin biopsies (removal of a small tissue sample under local anesthetic)\r\n\r\n  8. Buccal sample (gentle brushing inside the cheek to collect a cell sample) for gene\r\n   studies\r\n\r\n  Patients who request the results of their gene testing will be provided this information.\r\n " 
    }, 
    "detailed_description": { 
     "textblock": "\r\n  We propose to investigate the genetics of the scaling disorders and other genodermatoses\r\n  which are believed to behave in a Mendelian manner. Families for study will be ascertained\r\n  through articles in the Ichthyosis Focus, (the newsletter of the Foundation for Ichthyosis\r\n  and Related Skin Types), physician referrals, and patient self-referrals. Efforts will be\r\n  made to further characterize the clinical findings in both affected persons and unaffected\r\n  gene carriers. Using candidate genes, especially those known to be involved in structural\r\n  abnormalities of skin, we will attempt to map and isolate major genes contributing to\r\n  expression of the disease phenotype. Failing this direct approach, a random search of the\r\n  genome (so-called, \"reverse genetics\") will be utilized. In addition, normal and diseased\r\n  skin will be used in cell culture and animal experiments (under a separate protocol) to test\r\n  new therapeutic modalities.\r\n " 
    }, 
    "overall_status": "Completed", 
    "start_date": "February 1992", 
    "completion_date": "April 2001", 
    "phase": "N/A", 
    "study_type": "Observational", 
    "study_design": "N/A", 
    "condition": [ 
     "Genetic Skin Disease", 
     "Keratosis Follicularis", 
     "Lamellar Ichthyosis" 
    ], 
    "eligibility": { 
     "criteria": { 
     "textblock": "\r\n  No steroid sulfatase deficiency.\r\n  " 
     }, 
     "gender": "Both", 
     "minimum_age": "N/A", 
     "maximum_age": "N/A", 
     "healthy_volunteers": "Accepts Healthy Volunteers" 
    }, 
    "location": { 
     "facility": { 
     "name": "National Cancer Institute (NCI)", 
     "address": { 
      "city": "Bethesda", 
      "state": "Maryland", 
      "zip": "20892", 
      "country": "United States" 
     } 
     } 
    }, 
    "location_countries": { 
     "country": "United States" 
    }, 
    "reference": [ 
     { 
     "citation": "DiGiovanna JJ, Bale SJ. Epidermolytic hyperkeratosis: applied molecular genetics. J Invest Dermatol. 1994 Mar;102(3):390-4. Review.", 
     "PMID": "7509838" 
     }, 
     { 
     "citation": "Russell LJ, DiGiovanna JJ, Rogers GR, Steinert PM, Hashem N, Compton JG, Bale SJ. Mutations in the gene for transglutaminase 1 in autosomal recessive lamellar ichthyosis. Nat Genet. 1995 Mar;9(3):279-83.", 
     "PMID": "7773290" 
     } 
    ], 
    "verification_date": "April 2000", 
    "lastchanged_date": "March 4, 2008", 
    "firstreceived_date": "November 3, 1999", 
    "keyword": [ 
     "DNA Markers", 
     "Family Studies", 
     "Gene Mapping", 
     "Ichthyosis", 
     "Keratin", 
     "Linkage Analysis", 
     "Scaling Disorders", 
     "Skin" 
    ], 
    "has_expanded_access": "No", 
    "condition_browse": { 
     "mesh_term": [ 
     "Darier Disease", 
     "Skin Diseases" 
     ] 
    } 
    } 
} 

回答

0

尝试一下,看看它是如何工作的,将城市转换为正则表达式格式,“|”只适用于城市有多个以空格隔开的名称,例如(纽约)。

String regex = String.Format("({0})", String.Join("|", TextBox2.Text)); 
var query  = Query.Matches("clinical_study.location.facility.address.city", regex); 
var query2 = collection.Find(query);