Mongoose opts for the __v field over a traditional date field

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?

Answer №1

Your schema contains a typographical error with d**a**fault instead of default

The __v serves as a version identifier for the document, allowing you to exclude it from your search queries using .select(-__v)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Image caption dynamically updated to match thumbnail caption using jQuery upon click event

My goal is to dynamically load the data-caption of thumbnail images when clicked, and then update the main image's data-caption when the main image is changed with a thumb image. I am currently struggling to make the data-caption update along with the ...

Trouble arises with AJAX due to DOM traversal errors

I am trying to set up a system for liking and disliking with a counter. However, I am facing issues with my AJAX call, specifically when attempting to change the HTML of selected elements in the view after sending values to the DB. The element in question ...

What are the best practices for creating and displaying functional components effectively?

I'm in the process of building and displaying a functional component following the guidelines provided as a starting point. After reviewing the instructions, it seems like I should be able to achieve something similar to this: class MyComponent exten ...

Prevent certain dates from being selected in a designated input field

I am facing an issue with disabling certain array dates for a specific input field in a datepicker calendar. Even though I have included the script to exclude those dates, they are not getting disabled for that particular input field. html <input cla ...

What is the process for removing a document attribute in Sanity iO?

I have a collection of objects within my Sanity Document named Images which includes Comments An example comment object in the comments array looks like: { "_key": "6510dc79cf8b", "comment": "Hello world" ...

Maintaining selected options in select lists while updating model data in Angular

New to Angular and exploring the Product object with Sku objects nested inside. An app allows users to fetch a product, resulting in the Product object being assigned to $scope.product: var app = angular.module('app', []); app.controller(&apos ...

Ways to modify the shown data in dojox DropDownSelect

I have a DropDownSelect element set up with the following HTML tags: <select id="someId" dojoType="dojox.form.DropDownSelect" > <option>Loading...</option> </select> Now, when the xhr load function is triggered, I want to replace ...

Combining the chosen value from a combo box to display in a label using ExtJs 3.4

In my form panel, I have an Ext combo box set up like this: new Ext.form.ComboBox({ store : routeStore, displayField : 'rName', valueField : 'rName', fieldLabel : 'Select Fixed Route', id : 'routeComb ...

Delay loading of external JavaScript with data attributes

Exploring options for lazy loading this code snippet: <script async src="https://comments.app/js/widget.js?3" data-comments-app-website="TvibSQx_" data-limit="5" data-color="29B127" data-dislikes="1" dat ...

Modifying the color of an individual object in THREE.js: Step-by-step guide

I am currently working on editing a program that uses Three.js and Tween.js. Despite my efforts to find a solution both here and online, I have not been successful. The program involves creating multiple objects (cones) using THREE.Mesh, with a script that ...

Creating with NodeJS

I'm encountering an issue where my code is not waiting for a response when trying to retrieve data from a database. The connection is fine and everything works well, but Express isn't patient enough for the data to come through. Despite trying v ...

What is the best way to design a footer that remains fixed at the bottom of the screen but becomes unfixed when the user scrolls down?

Currently, I am working on creating a footer that remains fixed at the bottom of the user's screen regardless of the screen size. However, I also want the header to transition from a fixed position to being part of the page when the user scrolls down. ...

Unable to store the hashed password using bcrypt

I've been working on persisting hashed passwords using sequelize, bcrypt, and express. While the hash is being generated, it seems like the database entry occurs before the hash value is ready. My understanding of NodeJS is still in its early stages. ...

The issue I am experiencing within my PHP code is that the redirection to the gratitude page is not functioning correctly when utilizing

As a newcomer to PHP, I have been struggling with an example code from a website that is not redirecting to the thank you page as expected. Moreover, the email functionality is not working properly either. The code was sourced from: Upon downloading the f ...

Having trouble with my sorting algorithm - am I overlooking something obvious?

function Controller($scope) { var sortItems = [ { "text": "Second", "a": 2 }, { "text": "Fifth", "a": 5 }, { "text": "First", "a": 1 }, { "text": "Fourth", "a": 4 }, { "text": "Third", "a": 3 } ]; va ...

Angular controller utilizing the `focusin` and `focusout` events from jQuery

Can anyone help me figure out why this piece of code is generating syntax errors in my AngularJS controller? $(".editRecur").focusin(function() { $(.recurBox).addClass("focus"); }).focusout(function() { $(.recurBox).removeClass("focus"); }); ...

ASP.NET - The Power of a Long Press

I am currently working on implementing a Long Press event in JavaScript on an ASPX page. Due to my limited experience with JavaScript, I am facing a few challenges. I found a similar question that was previously asked here. When running the code, I encoun ...

Error encountered with jQuery XML: 'Access-Control-Allow-Origin' header is not present on the requested resource

For a personal project I'm working on just for fun, I'm trying to read an XML file from , parse the data, and use it to convert currency values. Although my code to read the XML is quite basic, I encountered the following error: XMLHttpRequest ...

Converting API response into a class instance using `class-transformer` in TypeScript: A step-by-step guide

When working with TypeScript, I have a regular method called Request(method: HttpMethod, url: string, ...) that is used for calling APIs. Now, my goal is to convert the response from this API request into an instance of a class using class-transformer (or ...

Issue encountered when using Material-UI Button's onClick() function: "Uncaught TypeError: Unable to access 'name' property of undefined" error is thrown

I have been facing an issue with a Material UI button that has an OnClick function. Strangely, when I try to click on the button, it doesn't seem to work and instead shows an error message. Could anyone please point out what might be going wrong here ...