Find objects between two dates MongoDB

后端 未结 14 2079
余生分开走
余生分开走 2020-11-21 06:03

I\'ve been playing around storing tweets inside mongodb, each object looks like this:

{
\"_id\" : ObjectId(\"4c02c58de500fe1be1000005\"),
\"contributors\" :          


        
14条回答
  •  难免孤独
    2020-11-21 06:20

    MongoDB actually stores the millis of a date as an int(64), as prescribed by http://bsonspec.org/#/specification

    However, it can get pretty confusing when you retrieve dates as the client driver will instantiate a date object with its own local timezone. The JavaScript driver in the mongo console will certainly do this.

    So, if you care about your timezones, then make sure you know what it's supposed to be when you get it back. This shouldn't matter so much for the queries, as it will still equate to the same int(64), regardless of what timezone your date object is in (I hope). But I'd definitely make queries with actual date objects (not strings) and let the driver do its thing.

提交回复
热议问题