Retrieve the timestamp difference by querying mongoDb

Looking for a way to subtract days from a Date field. I tried the following query:

{"lastSeen": { "$gte": {"$date": { $subtract: [ "$date", 1616000000 ] }}}}

Unfortunately, it didn't work and I encountered an error on Gamesparks:

Error parsing JSON. Please ensure that your JSON is valid, including double-quotes on object keys.

Any suggestions would be greatly appreciated. Thank you.

Answer №1

To properly work with this JSON file, make sure to enclose $subtract in quotation marks.

{"lastVisited": { "$gte": {"$date": { "$subtract": [ "$date", 1616000000 ] }}}}

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

What is the easiest way to simulate the Ctrl+C key event using jQuery?

I need to programmatically simulate pressing Ctrl+C in order to copy text from a page. My initial attempt looked like this: $('#codetext').click( function() { $("#codetext").trigger({ type: 'keydown', which: 99 }); } Her ...

Looping through a JavaScript array, eliminating duplicates based on a specific value, and then adding the unique value along with another value to a new array

When receiving an array of objects through an API call in my Vuejs front-end application, I faced the task of looping through the data to eliminate duplicates and create a new array containing unique "phases" along with their respective "id's". The or ...

Struggling to make the AJAX script function properly

I have a table containing a list of transactions and I am attempting to update the table contents at specific intervals. The web page is hosted on a Linux Red Hat server, and currently, only the AJAX functionality is not functioning as expected. <!do ...

What are the steps to modify data within the root component?

I am currently working on a Vue project with vue-cli and routes. In my App.vue file, the template structure is as follows: <template> <div id="app"> {{Main}} <router-view></router-view> </div> </template&g ...

How can I use Node.js Express to upload files with Multer?

I am facing an issue while trying to upload a file image using multer in express. The file gets successfully uploaded to the directory, but the name of the file is not being saved in the database. I am utilizing mongodb with express and currently, the file ...

When the cursor hovers, a drop-down menu appears simultaneously

Currently utilizing the Bigcommerce stencil theme, I have encountered an issue where both dropdown menus appear when I hover over a link. My goal is to have only one dropdown menu pop up when hovering over a specific link. https://i.sstatic.net/paVoY.png ...

Interrogate an array following population with mongoose.js

I'm facing a challenge when trying to query an array of references after populating with their corresponding objects. It seems like I might be using the wrong operational $... or my approach might not be the most efficient way to achieve what I want. ...

Encountered an unforeseen token "<" that is causing the server to return a 404 HTML page instead of the intended .js

I am currently developing a to-do list application using Node.js Express and EJS. In the app, I have implemented a filtering functionality with a URL path of "/filter/query". Based on the selected category (either "lists" or "lastupdated"), the app filters ...

Delete a particular item from a JSON object in real-time using TypeScript/JavaScript

Upon examining the JSON data provided, it contains a node called careerLevels which includes inner child elements. input = { "careerLevelGroups": [ { "201801": 58, "201802": 74, ...

In the production mode, Webpack doesn't compile any code

I recently followed the typescript guide at https://webpack.js.org/guides/typescript/ After running webpack in "production" mode, I noticed that it emitted very minimal output. Below is the code from my src/index.ts file: export function foo() { return ...

How can we implement the MUI snackbar to only show when a successful login occurs in ReactJS?

How can I display the material-ui snackbar in ReactJS only upon successful login? What approaches can be used to achieve this in ReactJS? ...

Execute the controller function a single time for two divs that share the same controller

I'm currently working on my project using angularjs. I have implemented two divs that share the same controller. Here is the code for my controller: var app=angular.module('categoryPageApp', []); app.controller('NgProducts', funct ...

Retrieve information from an external JSON source

I am receiving data from an API and storing its JSON in a separate file. The unique URL for accessing this file is shown below: http://events.com/rsvp.php?id=1234 The JSON content on the specified page appears like this: { rsvp: true } Each contact ha ...

Verify if the upcoming element possesses a particular class

Here is the HTML structure: <div class="row"> <div class="span"></div> <div class="span"></div> <div class="navMenu"> <ul> <li><a href=#">Link 1</a></li> ...

Another exciting discussion on converting JSON to an HTML table

While I know that asking a question without providing any code is generally discouraged, I am feeling quite lost at the moment. I have some basic JSON files that follow a structure similar to the example below: [{ "key1" : "some value", "key2" : 1 ...

What makes MongoDb a better choice than MySql for NodeJs development?

Please take note: I am looking for factual answers only, not opinions or debates on the topic of "nosql vs sql which is better". My goal is to gradually transform a Symfony2 website I built with php+mysql into a real-time application using backbone with n ...

Finding the positions of elements in an array

My challenge involves working with a collection that contains the following document { "_id" : ObjectId("4e8ae86d08101908e1000001"), "food" : ["Apples", "Banana", "Grapes", "Pear"], ...

Load Bootstrap 4 Modal with Ajax

I recently upgraded from Bootstrap 3 to Bootstrap 4.1 Within my applications, I utilize ajax loaded modals. In the layout, I have: <div class="modal fade" id="myModalToFillInfo" tabindex="-1" role="dialog" aria-labelledby="myModalToFillInfoLabel" ari ...

What causes the data property to supersede the return false in a jQuery ajax call?

Below is a block of code that I am currently working with: $("#contact_container form, #contact_details form").live( "submit", function(event) { $.ajax({ type: this.method, url: this.action, data: this.s ...

Navigating Angular on Internet ExplorerUnderstanding Angular's Compatibility

Having some trouble with an Angular app I'm developing. It displays perfectly on Chrome, but not at all on IE. Any tips on how to configure IE to show it correctly, or should I make changes to the app to ensure compatibility with IE? You can see how i ...