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

timestamp not created from Schema #14041

Closed
1 task done
popeating opened this issue Nov 2, 2023 · 4 comments
Closed
1 task done

timestamp not created from Schema #14041

popeating opened this issue Nov 2, 2023 · 4 comments
Labels
can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity. Stale

Comments

@popeating
Copy link

Prerequisites

  • I have written a descriptive issue title

Mongoose version

8.0.0

Node.js version

20.9.0

MongoDB version

6.0.11

Operating system

Windows

Operating system version (i.e. 20.04, 11.3, 10)

11

Issue

when creating a basic schema, i enabled timestamps, but when saving new documents timestamps are not attached:
this is my schema:

import { Schema, model, models } from 'mongoose';
const contactSchema = new Schema(
  {
    name: { type: String, required: true },
    email: { type: String, required: true },
  },
  { timestamps: true }
);
const Contact = models.contact || model('Contact', contactSchema);
export default Contact;

and this is how i save a new document:

const contact = new Contact(data);
contact.save();

what am i missing?

@popeating popeating added help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary help wanted labels Nov 2, 2023
@vkarpov15 vkarpov15 added this to the 8.0.1 milestone Nov 3, 2023
@vkarpov15 vkarpov15 added needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue and removed help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary help wanted labels Nov 3, 2023
@IslandRhythms IslandRhythms added can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity. and removed needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue labels Nov 3, 2023
@IslandRhythms
Copy link
Collaborator

Please modify the script below to demonstrate your issue

const mongoose = require('mongoose');

const testSchema = new mongoose.Schema({
  name: String,
  email: String
}, { timestamps: true });

const Test = mongoose.model('Test', testSchema);

async function run() {
  await mongoose.connect('mongodb://localhost:27017');
  await mongoose.connection.dropDatabase();

  const doc = new Test({ name: 'Test Testerson', email: 'test@localhost.com' });
  await doc.save();
  console.log('what is doc', doc);
}

run();

image

@Automattic Automattic deleted a comment from donoftime2018 Nov 4, 2023
@Automattic Automattic deleted a comment from donoftime2018 Nov 4, 2023
@Automattic Automattic deleted a comment from donoftime2018 Nov 4, 2023
@Automattic Automattic deleted a comment from donoftime2018 Nov 4, 2023
@Automattic Automattic deleted a comment from donoftime2018 Nov 4, 2023
@Automattic Automattic deleted a comment from donoftime2018 Nov 4, 2023
@vkarpov15
Copy link
Collaborator

@popeating how are you determining that timestamps aren't being attached?

@vkarpov15 vkarpov15 removed this from the 8.0.1 milestone Nov 4, 2023
@Automattic Automattic deleted a comment from donoftime2018 Nov 6, 2023
Copy link

This issue is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days

@github-actions github-actions bot added the Stale label Nov 21, 2023
Copy link

This issue was closed because it has been inactive for 19 days and has been marked as stale.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity. Stale
Projects
None yet
Development

No branches or pull requests

3 participants