moon
moon

Reputation: 165

How can I use ISODate in NosqlUnit data set file(MongoDB)

I am using NosqlUnit, Fongo, Spring-Data-MongoDB

my dataset format like below.

{
    "people" : {
        "data" : [
            {
                "key" : "12345",
                "phone" : "33333",
                "register" : "2011-01-05T10:09:15.210Z", //It is ISODate, How can I convert Joda DateTime?
                "index" : 1
            }
        ]
    }
}

my domain object like this,

  @Id
  private ObjectId id;

  @Field("key")
  private String key;

  @Field("phone")
  private String phone;

  @Indexed(unique=true, direction=IndexDirection.DESCENDING)
  @Field("index")
  private long index;

  @Field("register")
  private DateTime register;

But register always null

Thanks for your help

Upvotes: 0

Views: 287

Answers (1)

Marc Tarin
Marc Tarin

Reputation: 3169

Since you didn't bother to forward the answer that was given to you on the fongo repository issue section...

Use the MongoDB extended JSON strict mode notation for dates, using the ISO 8601 UTC notation (not the one with localtime and timeoffset that is parsed incorrectly), as explained here and here:

{
    "people" : {
        "data" : [
            {
                "key" : "12345",
                "phone" : "33333",
                "register" : { "$date" : "2011-01-05T10:09:15.210Z" }, 
                "index" : 1
            }
        ]
    }
}

Upvotes: 0

Related Questions