seppevs / migrate-mongo

A database migration tool for MongoDB in Node
MIT License
931 stars 166 forks source link

insertMany is not adding timestamps to the Collection using migration script #422

Closed parth-007 closed 1 year ago

parth-007 commented 1 year ago

Describe the bug I have one collection and I want to populate it by using the migration script. I have one JSON, which I want to dump into collection using insertMany method

To Reproduce I have this model:

const SchoolSchema = new Schema(
    {
        name: {
            type: String,
        }
    },
    {
        timestamps: {
            createdAt: "created_at",
            updatedAt: "updated_at",
        },
    }
);

module.exports = School = mongoose.model("schools", SchoolSchema);

I want to populate this table by one JSON object, which is like below

[
   {
      name: "ABC"
   },
   {
      name: "PQR"
   }
]

Here's the migration script:

const schoolsData = require("schools.json");
module.exports = {
  async up(db, client) {
    // For Population
    await db.collection('schools').insertMany(schoolsData);
  },

  async down(db, client) {
    await db.collection('schools').drop();
  }
};

It does not add timestamps while adding the rows to the table.

Expected behavior Timestamps should be added

Additional context Please let me know If I am using this in a wrong way.

seppevs commented 1 year ago

This issue seems to be related to Mongoose, not migrate-mongo. I'm closing this.