NameError: name 'ISODate' is not defined

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Done
    • Priority: Minor - P4
    • None
    • Affects Version/s: 2.6.1
    • Component/s: None
    • None
    • Environment:
      osx10.7.5
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      I have a collections of data imported from CSV, each doc has at least one datetime in string format. I'm writing a python program to convert the string into ISODate. However, I'm getting error above: 'ISODate' is not defined! I also tried 'new Date' with the same result.

      Below is the basic python program:

      ****
      import pymongo
      import datetime

      connection = pymongo.MongoClient("mongodb://localhost")
      db = connection.cts
      projects = db.dces.projects

      1. All project has start date, update all projects
        projects.update({}, {'$set': {"start": ISODate('start')}})

      *****

      The average doc look like below:
      (these are cut & paste from mongo shell)

      > x = db.dces.projects.findOne()
      {
      "_id" : "OPER",
      "status" : "Started",
      "name" : "Small Projects",
      "stop" : "",
      "detail" : "Small project & daily operation request from DC customers",
      "start" : "2011-01-01T16:00:00",
      "pm" : "stsao"
      }
      > x.start
      2011-01-01T16:00:00
      > y= new Date(x.start)
      ISODate("2011-01-01T16:00:00Z")
      > z = ISODate(x.start)
      ISODate("2011-01-01T16:00:00Z")
      > db.dces.projects.update({_id:"OPER"},{$set:{start: y}})
      WriteResult(

      { "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 }

      )
      > x = db.dces.projects.findOne()
      {
      "_id" : "OPER",
      "status" : "Started",
      "name" : "Small Projects",
      "stop" : "",
      "detail" : "Small project & daily operation request from DC customers",
      "start" : ISODate("2011-01-01T16:00:00Z"),
      "pm" : "stsao"
      }

      I have search the python documentation with not much help. I can brute force it like I do in the shell, but I have well over 7000 datetime in string to change to ISO format, I would love to get the Python program. Or even in JS.

      Thanks.

            Assignee:
            A. Jesse Jiryu Davis
            Reporter:
            suchon tsaowimonsiri
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: