1

I have a problem with date and datetime inside runCommand of MongoDB. It has been saving my date in null. I could not use ISODate() because it give a error. The variable $date hasn't show me a error but it storged a null value.

This is the mongoDB's query string that I'm executing from Java application:

{
  q: {
    'person_id': '1003', 'authoriz.auth_id': { $ne: '1025' }  },
  u: {
    $addToSet: {
      'authoriz': {
        'decision': "TRUE",
        'start_date': { $date: "2018-02-09 00:00:00.0" },
        'decision_id': 125,
        'decision_dsc': "PERMITED",
        'block_id': "1025"
      }
    },
    $currentDate: {
      'last_modified': true
    }
  },
  multi: false,
  upsert: false
}

In Java:

DBObject dbObject = (BasicDBObject) JSON.parse(query);
CommandResult result =anyDB.command(dbObject);

Instead of save '2018-02-09 00:00:00.0' value in field start_date it has been storaging a null value.

Could you help me how I set up my query string to save the date? Are there any others option How I use date with runCommand?

JhonQO
  • 368
  • 3
  • 7

1 Answers1

1

You don`t have the ISO complaint string so the parser returns null.

Use ISO string and it will be fine. More here

Something like

"'start_date': { $date: \"2018-02-09T00:00:00.000Z\" }"

Btw command is low level interface and you should be using methods like update, findAndModify provided in DBCollection.

s7vr
  • 73,656
  • 11
  • 106
  • 127