6

I am using com.mongodb.util.JSON.parse to parse a JSON file to DBObject. How do I specify dates, refs, and objects IDs in the JSON file?

1 Answer 1

8

Dates : { myDate: {$date: "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" } } // Date in the mentioned ISODate string format.

Refs : { myRef : { $ref : <collname>, $id : <idvalue>[, $db : <dbname>] } } // collname is collection name, idvalue is the _id of the referred document and optionally dbname is the database the document is in.

ObjectIds : { _id : {$oid: "4e942f36de3eda51d5a7436c"} }

Sign up to request clarification or add additional context in comments.

4 Comments

Can you please explain what you mean by a parseable string?
Any particular reason why you unaccepted. The information above is accurate.
Sorry, I meant to follow up. I have accepted the answer, but I am facing an issue. The Java library expects the data to be in the ISO date format (as a string), and not as a long as given above. When I use the long format, I get a JSON parse exception.
@jeffreyveon. Ah, yes, my apologies. The JSON.parse method expects the date as a string in the "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" format. I'll edit my answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.