Skip to content
This repository has been archived by the owner on Apr 15, 2023. It is now read-only.

Not save changes when Shema's timestamps option is provided #44

Open
dimaMachina opened this issue Nov 28, 2018 · 2 comments
Open

Not save changes when Shema's timestamps option is provided #44

dimaMachina opened this issue Nov 28, 2018 · 2 comments

Comments

@dimaMachina
Copy link

I found a bug, when Shema's timestamps option is provided, mongoose-history not work as expected. It save

{
  "_id" : ObjectId("5bff173396b3a40f7f560031"),
  "t" : ISODate("2018-11-28T22:31:15.528Z"),
  "o" : "u",
  "d" : {
    "updatedAt" : ISODate("2018-11-28T22:31:15.528Z")
  }
}

instead

{
  "_id" : ObjectId("5bff17fa596f180f8ffb35c8"),
  "t" : ISODate("2018-11-28T22:34:34.473Z"),
  "o" : "u",
  "d" : {
    "lastname" : "THIS",
    "firstname" : "Work?"
  }
}
@nassor
Copy link
Owner

nassor commented Dec 5, 2018

Which command are you using to update your document?

@bluepuma77
Copy link

Same here, using Typescript with mongoose 5.9. It doesn't save the changed fields.

import mongoose, { Schema, Document } from 'mongoose';
import mongooseHistory from 'mongoose-history';

export interface IDoc extends Document {
    code: string;
    room: string;
    createdAt: Date;
    updatedAt: Date;    
    createdBy: string;
    updatedBy: string;    
}

const DocSchema: Schema = new Schema(
    {
        code: { type: String, required: true },
        room: { type: String, required: true },
        createdBy: String,
        updatedBy: String,
    },
    {
        timestamps: true,
    }
);

DocSchema.plugin(mongooseHistory);

export default mongoose.model<IDoc>('Doc', DocSchema);

When I change the room with findOneAndUpdate I only get an updated timestamp in the logs:

{
  "_id": { "$oid":"5f3d1d5fd4450f53a0c4d9f8" },
  "t": { "$date":"2020-08-19T12:38:55.667Z" },
  "o": "u",
  "d": { "updatedAt": { "$date":"2020-08-19T12:38:55.666Z" } }
}

I tried with both options useFindAndModify: false and useFindAndModify: true.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants