Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7163277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:52:35+00:00 2026-05-28T13:52:35+00:00

Lets say I have a class User. A user got a name, gender, …,

  • 0

Lets say I have a class User. A user got a name, gender, …, born. When I got an userobject I can insert that in the database. Thats fine. There is just a problem with date. Im trying this:

String json = "{'name': '" + user.getName() + "', 'born': '" + user.getBorn() + "'}";
DBObject o = (DBObject)JSON.parse(json);
myCollection.insert(o); 

user.getBorn() is returning a Date, but in the database it is a string. So if Im reading it I get something like Fri Sep 05 00:00:00 GMT+01:00 1980 as a string and thats not good 🙂 I would like have a Date. So there is maybe more the one option(?) Maybe I could convert this DateString somehow to Date? Or maybe I could insert the document without a string? Thank you for any help!

Edit: ok Renato said I could use simpledateformat. And whats about the other option? How to put it as a Date() in the db?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:52:36+00:00Added an answer on May 28, 2026 at 1:52 pm

    It might be easier to use the BasicDBObjectBuilder like so:

    DBObject o = BasicDBObjectBuilder.start()
      .add("name", user.getName())
      .add("born", user.getBorn())
      .get();
    myCollection.insert(o);
    

    This will store the born value as a BSON date.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say we have User entity class. User can be friends with other users.
Lets say we have some basic AR model. class User < ActiveRecord::Base attr_accessible :firstname,
Lets say I have the following code: abstract class Animal case class Dog(name:String) extends
Lets say I have a class like this: Class User { var $id var
Lets say I have some view models set up as follows: public class User
Lets simplify. Lets say I have this class: class Foo { public string Name
Say I have a page in my web application that lets a user update
I have a class that has a function, lets say class.php: class fun {
Let's say I have two objects: User and Race. class User attr_accessor :first_name attr_accessor
Lets say I have this class in foobar-shared.lib: class FooBar { std::string m_helloWorld; }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.