{
  "slug": "Struggle-with-export-and-import-in-MongoDB-via-mongo-express-c64c0154937",
  "title": "Struggle with export and import in MongoDB via mongo-express",
  "subtitle": "In a previous article, I mentioned that I have to use mongo-express to import and export data from my local server, which causes some…",
  "excerpt": "In a previous article, I mentioned that I have to use mongo-express to import and export data from my local server, which causes some…",
  "date": "2022-08-09",
  "tags": [
    "My Experience",
    "Node.js",
    "MongoDB"
  ],
  "readingTime": "1 min",
  "url": "https://medium.com/@mobinshaterian/struggle-with-export-and-import-in-mongodb-via-mongo-express-c64c0154937",
  "hero": "https://cdn-images-1.medium.com/max/800/1*ptlVYvX3Ppjw6npeC8o6kg.png",
  "content": [
    {
      "type": "paragraph",
      "html": "In a previous article, I mentioned that I have to use mongo-express to import and export data from my local server, which causes some trouble. When I export from my local, it has a date value import. The button is not working."
    },
    {
      "type": "image",
      "src": "https://cdn-images-1.medium.com/max/800/1*ptlVYvX3Ppjw6npeC8o6kg.png",
      "alt": "Export and Import Button in mongo-express",
      "caption": "Export and Import Button in mongo-express",
      "width": 290,
      "height": 303
    },
    {
      "type": "paragraph",
      "html": "After I pressed the export button, it made a JSON file like the below example."
    },
    {
      "type": "code",
      "lang": "json",
      "code": "{\n  \"_id\": {\n    \"$oid\": \"62ea6a73511c5f776039****\"\n  },\n  \"user_id\": \"d37d691e-cc94-4620-ab55-c1f98e1****\",\n  \"soft_delete\": false,\n  \"purchase_at\": {\n    \"$date\": \"2020-03-14T12:08:02Z\"\n  },\n  \"created_at\": {\n    \"$date\": \"2022-08-03T12:30:43.063Z\"\n  },\n  \"updated_at\": {\n    \"$date\": \"2022-08-03T12:30:43.063Z\"\n  }\n}"
    },
    {
      "type": "paragraph",
      "html": "But when imported into the server mongo-express, it doesn’t work. After many struggles with JSON files and server, I discovered the problem is related to the $date format."
    },
    {
      "type": "paragraph",
      "html": "So I tried different types of JSON made with Nosqlbooster and imported with the New Document button."
    },
    {
      "type": "image",
      "src": "https://cdn-images-1.medium.com/max/800/1*A1I00-d6CLc4XhV9KLg2sA.png",
      "alt": "Struggle with export and import in MongoDB via mongo-express",
      "caption": "",
      "width": 327,
      "height": 272
    },
    {
      "type": "paragraph",
      "html": "Instead of prevoius type of data for import data I used bellow types:"
    },
    {
      "type": "code",
      "lang": "json",
      "code": "{ \"_id\" : ObjectId(\"62ea6a73e2a83fe32a1****\"), \"user_id\" : \"d37d691e-cc94-4620\", \"numbery\" : 334,\n\"created_at\" : ISODate(\"2022-08-03T17:00:43.126+04:30\"), \"updated_at\" :\nISODate(\"2022-08-03T17:00:43.126+04:30\")}"
    },
    {
      "type": "image",
      "src": "https://cdn-images-1.medium.com/max/800/1*I-DkJjM6lFuLg34YaYb0Ww.png",
      "alt": "Struggle with export and import in MongoDB via mongo-express",
      "caption": "",
      "width": 584,
      "height": 451
    },
    {
      "type": "paragraph",
      "html": "And it so quickly adds to Mongo."
    },
    {
      "type": "image",
      "src": "https://cdn-images-1.medium.com/max/800/1*mis8Iz8-ksSdHhlLPiomdA.png",
      "alt": "Struggle with export and import in MongoDB via mongo-express",
      "caption": "",
      "width": 285,
      "height": 252
    },
    {
      "type": "heading",
      "level": 2,
      "text": "Insert 4000 records into Mongo via Mongo-Express and Nosqlbooster."
    },
    {
      "type": "paragraph",
      "html": "I used a select query from my local database and copied the JSON array in the below format."
    },
    {
      "type": "code",
      "lang": "javascript",
      "code": "db.myCollection.find({}).projection({}).sort({ _id: -1 }).limit(4000);"
    },
    {
      "type": "paragraph",
      "html": "Just I added array in front and end of JSON results."
    },
    {
      "type": "code",
      "lang": "javascript",
      "code": "[/* 1 createdAt:8/3/2022, 5:01:58 PM*/{ \"_id\" : ObjectId(\"62ea6abee2a83fe32a1****\"), \"user_id\" :\n\"2a15b17f-144f-4644-***\", \"price\" : NumberLong(\"10000\"), \"created_at\" :\nISODate(\"2022-08-03T17:01:58.806+04:30\"), \"updated_at\" : ISODate(\"2022-08-03T17:01:58.806+04:30\")},"
    },
    {
      "type": "code",
      "lang": "javascript",
      "code": "/* 2 createdAt:8/3/2022, 5:01:58 PM*/{ \"_id\" : ObjectId(\"62ea6abee2a83fe32a14****\"), \"user_id\" :\n\"2a15b17f-144f-4644-***\", \"price\" : NumberLong(\"10000\"), \"created_at\" :\nISODate(\"2022-08-03T17:01:58.806+04:30\"), \"updated_at\" : ISODate(\"2022-08-03T17:01:58.806+04:30\")},"
    },
    {
      "type": "code",
      "lang": "text",
      "code": "]"
    },
    {
      "type": "image",
      "src": "https://cdn-images-1.medium.com/max/800/1*Lj-QM_G0G26PfOqoD0cPtw.png",
      "alt": "Struggle with export and import in MongoDB via mongo-express",
      "caption": "",
      "width": 604,
      "height": 497
    },
    {
      "type": "paragraph",
      "html": "Subscribe to DDIntel <a href=\"https://ddintel.datadriveninvestor.com/\" target=\"_blank\" rel=\"noreferrer noopener\">Here</a>."
    },
    {
      "type": "paragraph",
      "html": "Join our network here: <a href=\"https://datadriveninvestor.com/collaborate\" target=\"_blank\" rel=\"noreferrer noopener\">https://datadriveninvestor.com/collaborate</a>"
    }
  ]
}
