My current model setup is causing unexpected behavior:
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const NewModelSchema = new Schema({
user: {
type: Schema.Types.ObjectId,
ref: "users",
},
date: {
type: Date,
default: Date.now,
},
});
module.exports = NewModel = mongoose.model(
"new_model",
NewModelSchema
);
I attempted to generate documents with the following function:
const saveDocument = function saveDocument(user_id) {
const document_data = {
user: user_id,
};
const new_document = new NewModel(document_data);
const document = new_document.save();
return document;
};
Strangely, instead of creating the 'date' field, it creates the __v
field.
Here are examples of two documents I've created:
[
{
"_id": "60eb01a29e84151343183f4d",
"__v": 0
},
{
"_id": "60eb03ccc465491984b3bf99",
"__v": 0
}
]
Any thoughts on what could be causing this issue?