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.

After I pressed the export button, it made a JSON file like the below example.

json
{
  "_id": {
    "$oid": "62ea6a73511c5f776039****"
  },
  "user_id": "d37d691e-cc94-4620-ab55-c1f98e1****",
  "soft_delete": false,
  "purchase_at": {
    "$date": "2020-03-14T12:08:02Z"
  },
  "created_at": {
    "$date": "2022-08-03T12:30:43.063Z"
  },
  "updated_at": {
    "$date": "2022-08-03T12:30:43.063Z"
  }
}

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.

So I tried different types of JSON made with Nosqlbooster and imported with the New Document button.

Struggle with export and import in MongoDB via mongo-express

Instead of prevoius type of data for import data I used bellow types:

json
{ "_id" : ObjectId("62ea6a73e2a83fe32a1****"), "user_id" : "d37d691e-cc94-4620", "numbery" : 334,
"created_at" : ISODate("2022-08-03T17:00:43.126+04:30"), "updated_at" :
ISODate("2022-08-03T17:00:43.126+04:30")}
Struggle with export and import in MongoDB via mongo-express

And it so quickly adds to Mongo.

Struggle with export and import in MongoDB via mongo-express

Insert 4000 records into Mongo via Mongo-Express and Nosqlbooster.

I used a select query from my local database and copied the JSON array in the below format.

javascript
db.myCollection.find({}).projection({}).sort({ _id: -1 }).limit(4000);

Just I added array in front and end of JSON results.

javascript
[/* 1 createdAt:8/3/2022, 5:01:58 PM*/{ "_id" : ObjectId("62ea6abee2a83fe32a1****"), "user_id" :
"2a15b17f-144f-4644-***", "price" : NumberLong("10000"), "created_at" :
ISODate("2022-08-03T17:01:58.806+04:30"), "updated_at" : ISODate("2022-08-03T17:01:58.806+04:30")},
javascript
/* 2 createdAt:8/3/2022, 5:01:58 PM*/{ "_id" : ObjectId("62ea6abee2a83fe32a14****"), "user_id" :
"2a15b17f-144f-4644-***", "price" : NumberLong("10000"), "created_at" :
ISODate("2022-08-03T17:01:58.806+04:30"), "updated_at" : ISODate("2022-08-03T17:01:58.806+04:30")},
text
]
Struggle with export and import in MongoDB via mongo-express

Subscribe to DDIntel Here.

Join our network here: https://datadriveninvestor.com/collaborate