Querying Mongodb with extended millisecond intervals

I have a collection that I need to export every 5 minutes based on the timestamp field.

When querying the collection, the maximum date is as follows:

db.testcol.find({},{_id : 0,ts : 1}).sort({ts:-1})      
2017-04-14 23:40:27.690Z

I converted it to milliseconds:  1492213227000

    ex:        max1=db.testcol.find({},{_id : 0,ts : 1}).sort({ts:-1})
               print (new Date(max1).getTime());

Now, when querying the collection, there should not be any rows with timestamps greater than 1492213227000.

ex: db.testcol.find({ts:{$gt:new Date(1492213227000)}},{_id : 0,ts : 1})

However, despite this query, the same value is still being seen.

2017-04-14 23:40:27.690Z

If you could provide assistance in resolving this issue, it would be greatly appreciated.

Thank you, Ashwin

Answer №1

Your timestamp is incomplete without the .690 part. To maintain accuracy, the equivalent milliseconds should be 1492213227690.

To retrieve data after this updated timestamp, use the following query:
db.testcol.find({ts:{$gt:new Date(1492213227690)}},{_id : 0,ts : 1})

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

Leveraging AJAX in Ruby on Rails

In my controller, I have a function that looks like this: def showRecipeIngredients ingredients = RecipeIngredient.where( "recipe_id = ?", params[:id]).all @html = "" ingredients.each do |i| @html = @html + "<p>#{Food.find_by_ndb ...

In the realm of asp.net mvc, JSON remains a mysterious and undefined

When working with ASP.NET MVC 3, I have encountered an issue regarding JSON in my AJAX calls. The application runs smoothly on my development machine when using Visual Studio. However, after publishing the same application and trying to access it through a ...

Tips for dynamically populating JSON data using a dropdown selection?

I am currently exploring HTML forms as a new web developer. I have been experimenting with displaying JSON data in a div based on a selection from a dropdown menu using jQuery in Chrome. However, my code does not seem to be functioning properly. Even tho ...

Learn the steps for inserting or updating data in a local JSON file solely through JavaScript

Currently, I am in the process of reading a JSON file and removing an element once it finds an exact match. My goal is to then push the remaining data back into the JSON file after deletion. readJsonFile("./objects.json", function(jsonData){ let parsedD ...

How to retrieve only the last value from a JSON object using jQuery's .html

I'm having an issue with jQuery("#someID").html. It seems to only display the last name from the JSON data. Here is the javascript code: <div class="row" id="fetchmember"> <script type="text/javascript"> jQuery('#group').cha ...

Retrieving a targeted data point from a JSON object

I am working with a json data that contains various properties, but I am only interested in extracting the uniqueIDs. Is there a way to retrieve ONLY the uniqueID values and have them returned to me as a comma separated list, for example: 11111, 22222? (I ...

Utilizing d3.js to filter a dataset based on dropdown selection

I am working with a data set that contains country names as key attributes. When I select a country from a dropdown menu, I want to subset the dataset to display only values related to the selected country. However, my current code is only outputting [obje ...

Convert a multidimensional array into a string using JavaScript

Currently, I'm in the process of generating an invoice for a collection of books and my intent is to submit it using ajax. However, when attempting to json encode the array of books within the invoice, I am encountering a setback where the value keeps ...

using variables as identifiers in nested JSON objects

Within my code, there is a JSON object named arrayToSubmit. Below is the provided snippet: location = "Johannesburg, South Africa"; type = "bench"; qty = 1; assetNumber = 15; arrayToSubmit = { location : { type : { 'qty' ...

My Ajax request in Javascript is encountering failure in Chrome due to AdBlock. What alternatives can I consider in this situation

Attempting to execute an ajax function $.ajax({ url: etsyURL, dataType: 'jsonp', success: function(data) { However, when running it on Chrome in a live environment, it fails due to adblock. I rely on javascript/jquery as my primary tools. Any ...

JSONP is unable to utilize data fetched from an external API

I attempted to run an ajax request in order to retrieve a collection of items and display them through logging: https://i.stack.imgur.com/IK1qy.jpg However, when checking the console, the items appear as undefined: https://i.stack.imgur.com/3WOCa.jpg O ...

How to extract the value of a key from JSON using JavaScript

Need help with an API call to retrieve a list of subcategories? Here's an example of the JSON format: { "description": "Flower", "name": "Flower", "parent_id": "1" }, { "description": "Moon", "n ...

Obtaining HTML elements from JSON using jQuery (i.e., the opposite of serializing with Ajax)

I am looking to extract values from a set of controls (INPUT, SELECT, TEXTAREA) within a DIV and send them as JSON via Ajax to a server. Utilizing jQuery's serializeArray makes this process easy. After sending the JSON data, I expect the server to re ...

Organize JSON data based on the timestamp

What is the most effective method for sorting them by timestamp using jquery or plain JavaScript? [{"userName":"sdfs","conversation":"jlkdsjflsf","timestamp":"2013-10-29T15:30:14.840Z"},{"userName":"sdfs","conversation":"\ndslfkjdslkfds","timestamp" ...

Refreshing the dropdownlist data from the database without the need to reload the entire page

I am searching for a way to refresh data in a dropdown list after clicking a button. It is crucial that only the dropdown list form reloads. // Controller View public ActionResult AddRelease() { var Authors = _context.Authors.ToList(); ...

What are the steps to decode a JSON response using jQuery?

Working on a fun little web app for my significant other and me to keep track of movies we want to watch together. I'm exploring using TheMovieDatabase.org's API (which only supports JSON) to simplify the process of adding movies to our list. The ...

C# fails to accurately interpret JSON Arrays

I'm dealing with a peculiar JSON issue. I am currently using ASP C# and have a View that sends a JS-Array to a Controller Action. Here is the JSON Data structure: public class MapData { public List<Point> Points { get; set; } } public cla ...

I have a json file that I need to convert to a csv format

I am currently working with a json file, but I need to switch it out for a csv file. Do I have to use a specific library to accomplish this task, or can I simply modify the jQuery 'get' request from json to csv? I attempted the latter approach, b ...

What is the convention for using one-letter function names in jQuery and JSON?

Could someone please clarify the functionality of this code snippet? One aspect that I find frustrating about this function is its use of a single-lettered name. How can I determine the purpose of this function and what triggers it to run? function ...

Is there a recent problem with the flickrAPI where the photo description is showing as undefined

For the last couple of years, my two websites have been successfully populating galleries using a simple FlickrAPI call with JSON and jQuery. However, they recently encountered an error that caused gallery population to fail. I've narrowed down the i ...