Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3307928
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:27:46+00:00 2026-05-17T21:27:46+00:00

In a MongoDB database, I have a collection of items, and each item stores

  • 0

In a MongoDB database, I have a collection of items, and each item stores its creation date. I need to query this collection by date. I tried:

db.items.findOne({date:{new Date(1285947037*1000)}})

but it isn’t returning anything. I got that timestamp using PHP ($date->sec, where $date is a MongoDate object from the database). So what’s the right way to do this? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:27:47+00:00Added an answer on May 17, 2026 at 9:27 pm

    The Date constructor expects a timestamp in milliseconds. The 1285947037 timestamp is in seconds, which is why you’re multiplying it by 1000.

    My guess is that the actual timestamp in the document contains milliseconds, e.g. 1285947037461 (note the 461 at the end). You’re multiplying the seconds by 1000, which results in 1285947037000. As you can see, these timestamp aren’t equal:

    1285947037461 // actual timestamp in MongoDB
    1285947037000 // value you calculated
    

    The problem lies with the MongoDate class: it loses the milliseconds precision, as you can read in the documentation. Here’s the quote:

    […] this means that any precision beyond milliseconds will be lost when the document is sent to/from the database.

    To find the document you’re looking for using the timestamp in seconds, you need something like this:

    db.foo.findOne(function () {
      // round the stored date to seconds and compare to timestamp
      return parseInt(this.date / 1000) === 1285947037
    })
    

    You can get the exact timestamp in milliseconds in the console, by using myDateObject.getTime().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In mongodb, I have a comments database with a collection of comments. Each comment
I am using mongoDB database. in which I have collection in below format. {
I ran the following query on a collection in my mongodb database. db.coll.find({field_name:{$exists:true}}).count() and
I am writing a Happstack server and I have a MongoDB database to connect
Mongodb Database: {thread: abc, message: hjhjh, Date: (2010,4,5,0,0,0)} {thread: abc, message: hjhjh, Date: (2009,3,5,0,0,0)}
I am trying to search a MongoDB database filtering on a specific data item.
This is a general question about mongodb database design, but the reason for my
i want to update all records in my database(mongodb),I tried to use command below
I'm trying to increment a value in a collection in my MongoDB database through
I have a large collection of 300 question objects in a database test .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.