A guide on converting UTC time and date to local time and vice versa with MongoDB and Mongoose/Express

When comparing dates, I need to take into account my local Timezone (Asia/Kolkata GMT+5.30).

var today = moment().toDate();
var tomorrow = moment().add(1,'days').toDate();

Moment : I am utilizing MomentJS for this task (but unsure if it's the right tool).

Deal.find({date:{$gte: today, $lt: tomorrow}},function(err, result){
        if(err) return console.log("Error" + err);
    //Code goes here.
});

The date in the

Deal.find({date:{$gte: today, $lt: tomorrow}},function(err, result){

is based on GMT, while today and tomorrow are in my LOCAL Timezone as mentioned earlier.

How can I handle this? My focus is solely on my local Timezone and I'm not concerned about whether it's UTC or GMT.

I am working with a standard Express4, MongoDB, Mongoose ODM stack.

Is there a method to preprocess and adjust the date variable to my local Timezone before passing it to the Deal.find mongoose query?

Answer №1

Dealing with this Robo Mongo Setup problem was quite frustrating.

When faced with the Robo Mongo Window,

  1. Navigate to Options.
  2. Opt for Display Dates IN.
  3. Select your Local Time Zone.

Once you follow these steps, everything should be working smoothly!

Cheers and a big thank you!

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

uib-datepicker-popup allowing for changing minimum mode dynamically

Is there a way to dynamically set the minMode of an Angular Bootstrap Datepicker? I managed to achieve this using the following code: <input type="text" ng-model="myDate" uib-datepicker-popup="{{datepickerFormat}}" datepicker-options="{& ...

Tips for utilizing the useContext hook in Next.js

I'm facing an issue with persisting information between different pages using nextjs and the useContext hook. Despite changing a variable in one page, it reverts back to its default value when navigating to another page. Below is a glimpse of the dir ...

Guide on utilizing mongodump for a single collection

What is the best method for transferring a single collection from one database to another using mongodump? Can you provide instructions on utilizing the command and its various options effectively? ...

Is it possible to trim a video using HTML code?

I am trying to find a way to crop a video using HTML 5. <video id="glass" width="640" height="360" autoplay> <source src="invisible-glass-fill.mp4" type="video/mp4"> </video> Currently, the video has a resolution of 640x360. However ...

"RecognitionAudio variable missing" and "InactiveRpcError occurred" [Utilizing the Google text-to-speech API]

I have a goal I'd like to achieve. A user communicates with a web browser. The web browser records the user's voice as a WAV file using Recorder.js and sends it to a server running on Google App Engine Standard environment with Python 3.7. The ...

Creating Typescript libraries with bidirectional peer dependencies: A complete guide

One of my libraries is responsible for handling requests, while the other takes care of logging. Both libraries need configuration input from the client, and they are always used together. The request library makes calls to the logging library in various ...

"Incorporate React Redux to dynamically load an endless stream of items in batches of x at a time

In order to efficiently display search results using React - Redux, I want to limit the number of displayed results while maintaining optimal performance. Here is my current approach for getting and displaying the results: handleSubmit(event) { event ...

Navigate through a JavaScript text file one line at a time

There is a text file with the following content: User:root Password:root123 My goal is to read this text file in JavaScript line by line and store it in an array. Then, I want to split each value in the array using a colon (:). Despite trying multiple a ...

The web application encountered an error: "Uncaught TypeError: Cannot read property 'map' of undefined" when trying to retrieve

Struggling with a simple API fetch, and despite checking everything multiple times, I can't seem to figure out what's going wrong. It feels like I'm missing something crucial. import { useState } from "react"; import ProductCard fr ...

Creating individual components for <select> and <option> elements in ReactJS

I am uncertain about how references function when the select and option tags are used together. When I split them into separate React components, they stop working. How can I resolve this issue? Here is a basic example: <select> {() => ( ...

Effective approach for managing a series of lengthy API requests

I am developing a user interface for uploading a list of users including their email and name into my database. After the upload process is complete, each user will also receive an email notification. The backend API responsible for this task is created u ...

Using AngularJS to link a model referenced in the view (ng-bind) to a $resource obtained from an API

I'm currently facing a challenge in Angular where I need to establish a connection between a database object displayed in the html view and its corresponding instance through a json API. While I have a functioning api and $resource, I am struggling t ...

What is the process for retrieving an object from a node.js server using JSON.stringify() in a JavaScript file?

Looking to organize my code, I want to separate the JavaScript from my page and link it through a file instead of having it embedded within script tags. The issue arises when I receive a "SyntaxError: expected expression, got '<' " in Firefox ...

Increased/Decreased impact

Can someone explain how the "Tell me more" effect is achieved on the website linked below? I'm familiar with the read more/less effect in jQuery, but what intrigues me is that the page cannot be scrolled unless the button is clicked. Here is the link ...

Harnessing the power of Jquery within a Node Js environment

I've been encountering an issue with implementing JQuery in my Node Js Code. Below is the Node JS code I'm working with: var http = require('http'), fs = require('fs'); fs.readFile('./index.html', function (err ...

Decrease a value stored in a mongodb database

Currently, I am developing a shopping application where each user has their own wallet. The structure is as follows: { "userName" : "Gandalf the Grey", "wallet" : 100, "orderHistory" : [] } Let's say a user purchases an item that costs ...

What is the best practice for logging information and errors in a backend system that utilizes services and controllers?

As a backend developer, my approach to logging messages typically involves utilizing controllers like this: router.get('/books', async () => { const books = await booksService.getAll() logger.info('All books returned successfully') ...

What is the best way to add an array of objects to MongoDB using Golang and the official MongoDB Driver?

I'm currently facing an issue with inserting an array of objects and adding new objects to the existing array. The problem arises when I insert the array, resulting in an object nested inside an array within the parent array. Below is a snippet of my ...

"Troubleshooting the ineffectiveness of JavaScript's

(After reviewing all questions and answers related to this issue, I have not found a solution that works for me.) Here is the code snippet in question: var timeoutHandle; function showLoader(show) { if (show) { $('.loader').html(&a ...

Is there a way for me to automatically update my URL with different API IDs as I iterate through a JSON array?

While iterating through my JSON file, I use a forEach loop to extract all the IDs like this: var gameId = request("https://api.sportradar.us/ncaamb-t3/games/" + yyyy + "/" + mm + "/" + dd + "/schedule.json?api_key=************", function(error, response, ...