Search code examples
mongodbmongodb-querymern

Not able to query the JSON data converted from CSV


I'm trying to run below JSON data which is basically from CSV file. I am able to get output only in db.learning.find({})

while when I try to access specific document then it dont give any output.

JSON data is here below

/* 1 */
{
    "_id" : ObjectId("624edebb78036379835d29a7"),
    "pmid" : 32339032,
    "ti" : "SAFETY AND EFFICACY OF DDP4-INHIBITORS FOR MANAGEMENT OF HOSPITALIZED GENERAL MEDICINE AND SURGERY PATIENTS WITH TYPE 2 DIABETES.",
    "year" : "2020",
    "population" : "['general medicine and surgery patients with T2D', 'general medicine and surgery patients with type 2 diabetes (T2D', 'n=266) and surgery (n=319) patients admitted with a blood glucose (BG) between 140 and 400 mg/dl, treated with']",
    "population_mesh" : "[{'cui': 'C0086343', 'cui_str': 'General medicine'}, {'cui': 'C0038895', 'cui_str': 'operative procedures'}]",
    "journal" : "Endocrine practice : official journal of the American College of Endocrinology and the American Association of Clinical Endocrinologists",
    "dois" : "['10.4158/EP-2019-0481']"
}

/* 2 */
{
    "_id" : ObjectId("624edebb78036379835d29a8"),
    "pmid" : 32339033,
    "ti" : "SAFETY AND EFFICACY OF DDP4-INHIBITORS FOR MANAGEMENT OF HOSPITALIZED GENERAL MEDICINE AND SURGERY PATIENTS WITH TYPE 2 DIABETES.",
    "year" : "2021",
    "population" : "['general medicine and surgery patients with T2D', 'general medicine and surgery patients with type 2 diabetes (T2D', 'n=266) and surgery (n=319) patients admitted with a blood glucose (BG) between 140 and 400 mg/dl, treated with']",
    "population_mesh" : "[{'cui': 'C0086343', 'cui_str': 'General medicine'}, {'cui': 'C0038895', 'cui_str': 'operative procedures'}]",
    "journal" : "Endocrine practice : official journal of the American College of Endocrinology and the American Association of Clinical Endocrinologists",
    "dois" : "['10.4158/EP-2019-0481']"
}

i.e) db.collectionName.find(year:"2020") and other similar query dont give any output so Is there any problem in JSON data or my mongo shell command ?


Solution

  • when I changed two fields of JSON form string data to array of field by removing "" I was able to run the query

    reformed JSON is here which give the output. I dont know how its happen. But I got the result

    {
      "_id": {
        "$oid": "624edebb78036379835d29a7"
      },
      "pmid": 32339032,
      "ti": "SAFETY AND EFFICACY OF DDP4-INHIBITORS FOR MANAGEMENT OF HOSPITALIZED GENERAL MEDICINE AND SURGERY PATIENTS WITH TYPE 2 DIABETES.",
      "year": "2020",
      "population": [
        "general medicine and surgery patients with T2D",
        "general medicine and surgery patients with type 2 diabetes (T2D",
        "n=266) and surgery (n=319) patients admitted with a blood glucose (BG) between 140 and 400 mg/dl, treated with"
      ],
      "population_mesh": [
        {
          "cui": "C0086343",
          "cui_str": "General medicine"
        },
        {
          "cui": "C0038895",
          "cui_str": "operative procedures"
        }
      ],
      "journal": "Endocrine practice : official journal of the American College of Endocrinology and the American Association of Clinical Endocrinologists",
      "dois": "['10.4158/EP-2019-0481']"
    }