What is the syntax for Dates in MongoDB running on MongoLab?
Asked Answered
O

2

5

Instead of ObjectId('82he921he982he82') its "_id":{"$oid":"82he921he982he82"} for object Ids, but I have no idea how to create a date value in a document on MongoLab :s

Overwrought answered 4/11, 2011 at 6:34 Comment(0)
O
12

If you are using one of the drivers, you create a date via that language's Date class. For instance, in Javascript (like Node.js) it would be 'new Date(11,11,11)'. If using the MongoLab REST API or admin UI you represent dates with this syntax:

  { "$date": "2010-10-28T23:07:11Z" }
Overprize answered 4/11, 2011 at 6:40 Comment(1)
Thanks! I should have known it was that simple :pOverwrought
R
5

Also if an item has:

"dateAdded": {
   "$date": "2012-07-30T15:26:15.321Z"
}

in one of it's entries, then you can find it by searching:

{
    "dateAdded": {
        "$gt": {
            "$date": "2012-07-28T23:07:11Z"
        }
    }
}
Reformism answered 22/8, 2012 at 17:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.