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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:28:05+00:00 2026-06-12T01:28:05+00:00

I’m working on a NodeJS+Mongodb app. I’ve just inserted one record into mongodb using

  • 0

I’m working on a NodeJS+Mongodb app.

I’ve just inserted one record into mongodb using the console client:

db.user.save({myId:11111, myDate: ISODate("2012-04-30T00:00:00.000Z")})

The thing is, when I’m in node.js, I need to know if “myDate” field is really a Date type, in order to perform a data range query, etc.

I tried the following.

1. on the mongo client console:

typeof db.user.myDate --> It returns "Object"
db.user.myDate instanceof Date --> It returns "false"

2. on my Nodejs code,

I’m trying to get the type calling this getTypeMembers function. (obj comming from a db query)

exports.getTypeMembers = function(obj) {
obj = JSON.parse(JSON.stringify(obj)

for(var _k in obj){
    if(Object.prototype.toString.call(obj[_k]) === '[object Array]' ) {
        obj[_k] = "Array";
    }
    else if(typeof(obj[_k])=="object"){
        obj[_k] = this.getTypeMembers(obj[_k]);
    }else{
        obj[_k] = typeof (obj[_k]);
    }
}
return obj;

};

What I get in this method is: "String", when I need "Date"

Is there any other way to get some kind of "Date" result?

  • 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-12T01:28:06+00:00Added an answer on June 12, 2026 at 1:28 am

    I finally found my solution.

    As @christkv said, once you call a JSON stringify, all original types are definitely lost.
    So, thinking in this way, my method getTypeMembers works perfectly for me.

    Notice that, obj parameter is coming from the DB, and also “_id” (mongodb identificator) is directly ommited in order to avoid problems when performs the recursive function:

    exports.getTypeMembers = function(obj) {
        for(var _k in obj){
            if (_k =="_id") continue;
            if (Object.prototype.toString.call(obj[_k]) === "[object Number]"){
                obj[_k] = "Number";
            }else if (Object.prototype.toString.call(obj[_k]) === "[object String]"){
                obj[_k] = "String";
            }else if (Object.prototype.toString.call(obj[_k]) === "[object Date]"){
                obj[_k] = "Date";
            } else if(Object.prototype.toString.call(obj[_k]) === '[object Array]' ) {
                obj[_k] = "Array";
            } else if(typeof(obj[_k])=="object"){
                obj[_k] = this.getTypeMembers(obj[_k]);
            } else{
                obj[_k]  = (typeof obj[_k])[0].toUpperCase() + (typeof obj[_k]).slice(1);
            }
        }
        return obj;
    };
    

    In the Mongo console part, I only can get the type doing the following:

    db.user.find({},{myDate:1}).forEach(function(f) { print (f.myDate instanceof Date) } );
    

    But If I do,

    typeof db.user.myDate --> It returns "Object"
    db.user.myDate instanceof Date --> It returns "false"
    

    I still don’t undertand why.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am reading a book about Javascript and jQuery and using one of the
We're building an app, our first using Rails 3, and we're having to build
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm making a simple page using Google Maps API 3. My first. One marker
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.