mongoose-delete icon indicating copy to clipboard operation
mongoose-delete copied to clipboard

It would be better if there's an option for naming fields such as 'deletedAt'

Open chan-dev opened this issue 5 years ago • 3 comments
trafficstars

I'm using mongoose timestamps in my schema and they're in the format like this:

  timestamps: {
      createdAt: 'created_at',
      updatedAt: 'updated_at',
    }

I would like to rename deletedAt field to deleted_at. Is there a way to rename the field.

I tried using middleware like this. Using Bookmark.deleteById or Bookmark.restore invokes updateMany relative to my mongo version, so i have to use updateMany middleware.

The code below doesn't return the current doc updated

BookmarkSchema.post('updateMany', (doc, next) => {
  // This doesn't return the current document but rahter metadata of how many documents are updated
  console.log({ doc });
  next();
});

chan-dev avatar Sep 19 '20 06:09 chan-dev

I agree.. I'm trying to do this exact thing with my mongo objects and I haven't found a way to update the variable names created by this package.

arthur-alvesaf avatar Oct 17 '20 17:10 arthur-alvesaf

i ended up renaming my fields to follow the naming convention in this package. But it would still be better to allow renaming option here

chan-dev avatar Oct 19 '20 11:10 chan-dev

I agree with this as well, I ended up renaming all snake_case fields to match up with the camelCase convention this plugin use.

mohamedashrafothman avatar May 07 '23 02:05 mohamedashrafothman