Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timestamps schema options not applying to "createdAt" when depth is more than 1 #5051

Closed
JellyKid opened this issue Mar 8, 2017 · 1 comment
Milestone

Comments

@JellyKid
Copy link

JellyKid commented Mar 8, 2017

Weird issue here that I can't figure out if it's me or mongoose or mongo. When trying to customize the timestamp fields I can only get updatedAt to customize, while the createdAt field fails to show up... Please see below.

const schema = new mongoose.Schema(
  {
    firstName: String,
    lastName: String,
    email: String,
    initials: {type: String, default: 'AAA'},
    hash: {type: String, select: false},
    facebook: String,
    admin: {type: Boolean, default: false},
    enabled: {type: Boolean, default: false},
    meta: {
      authType: {type: String, default: 'local'},
      activated: {type: Boolean, default: false},
      invitationSent: Date,
      verificationToken: {type: String, select: false}
    }
  },
  {
    timestamps: {
      updatedAt: "meta.updatedAt",
      createdAt: "meta.createdAt"
    }
  }
);
> db.users.findOne({firstName: "test"})
{
        "_id" : ObjectId("58c01cde71a18209f40201a6"),
        "firstName" : "test",
        "lastName" : "user",
        "email" : "test@user.com",
        "meta" : {
                "activated" : false,
                "authType" : "local",
                "invitationSent" : ISODate("2017-03-08T15:01:50.618Z"),
                "verificationToken" : "6X9u8mxv00S9N8s6fXFcvlKY",
                "updatedAt" : ISODate("2017-03-08T15:01:50.618Z")
        },
        "enabled" : true,
        "admin" : false,
        "initials" : "AAA",
        "__v" : 0
}

If I set the createdAt field to something with a depth of 1, or don't try to customize the field it will set just fine.

@vkarpov15 vkarpov15 added this to the 4.8.8 milestone Mar 12, 2017
vkarpov15 added a commit that referenced this issue Mar 17, 2017
@vkarpov15
Copy link
Collaborator

This is a bug in mongoose, nested timestamp paths don't currently work, but will work when 4.9.1 lands (ETA Sunday March 19)

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

No branches or pull requests

2 participants