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 8456193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:29:03+00:00 2026-06-10T12:29:03+00:00

I have objects that use the keys updated_at and created_at which have string timestamps

  • 0

I have objects that use the keys updated_at and created_at which have string timestamps like 2012-08-29T16:04:34-04:00. I’m inserting this into MongoDB. The catch is each object can have a variable number of instances of updated_at and created_at (they are in arrays within). Is there any code out there that can be used to search an array for updated_at and created_at and replace the values with $.created_at = new Date($.created_at)?

{
    "name":"thomas",
    "created_at":"2012-08-29T16:04:34-04:00",
    "updated_at":"2012-08-29T16:04:34-04:00",
    "logs":[
        {
            "something":"something",
            "created_at":"2012-08-29T16:04:34-04:00",
        },
        {
            "something":"something",
            "created_at":"2012-08-29T16:04:34-04:00",
        },
    ]
}

to

{
    "name":"thomas",
    "created_at":new Date("2012-08-29T16:04:34-04:00"),
    "updated_at":new Date("2012-08-29T16:04:34-04:00"),
    "logs":[
        {
            "something":"something",
            "created_at":new Date("2012-08-29T16:04:34-04:00"),
        },
        {
            "something":"something",
            "created_at":new Date("2012-08-29T16:04:34-04:00"),
        },
    ]
}
  • 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-06-10T12:29:04+00:00Added an answer on June 10, 2026 at 12:29 pm
    // store your data object in x
    x = {
        "name":"thomas",
        "created_at":"2012-08-29T16:04:34-04:00",
        "updated_at":"2012-08-29T16:04:34-04:00",
        "logs":[
            {
                "something":"something",
                "created_at":"2012-08-29T16:04:34-04:00",
            },
            {
                "something":"something",
                "created_at":"2012-08-29T16:04:34-04:00",
            },
        ]
    }
    
    // create a traversal function to recurse
    function traverse(o) {
        // loop through object
        for (i in o) {
            // if it is a matched key (current regex matches created_at or updated_at)
            // parse the item as a date, and re-store object
            if(i.match(/(cre|upd)ated_at/)){
                o[i] = new Date(o[i])
            }
            // if the key we are looking at is an object, then recurse!
            if (typeof(o[i])=="object") {
                traverse(o[i])
            }
        }
    }
    
    // fire it up!
    traverse(x)
    
    // check the results
    console.dir(x)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several Entity Framework Code First DbContext objects that use a custom Initializer.
I have an object called users that I use to store user objects that
I have an ArrayList that I want to use to hold RaceCar objects that
I have a wrapper class around some objects that I want to use as
I have a Winforms application that dynamically instantiates external form objects for use in
I have an object at the root of plist that stores objects and keys
I have a singleton object that use another object (not singleton), to require some
It's Friday refactor time!!! I have an object that I use to generate SQL
I have been attempting to have a object that I can use across multiple
When you have an object that implements countable interface should you use $object->count() or

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.