0

for my MEAN stack project I have to store a Date object in MongoDB for the start and end of a booking. the Date goes in just fine, in my collection it's show as:

booking_start: 2022-12-16T00:00:00.000+00:00

booking_end:  2022-12-29T00:00:00.000+00:00

but when i query my collection for all entries the Dates come out as strings of numbers like this

                "booking_start": "1671148800000",
                "booking_end": "1672272000000"

what is going on here? I'll admit I'm new to working with Dates in Mongo but why is happening? I am using Graphql for my queries, but i don't think that the problem. is there a special way to query a Date?

here is my code and queries

resolver

        getuserbooking: async ()=>{
            const userListinglist = userbooking.find({})
            return userListinglist
        }

it's schema

type Query {
       
        getuserbooking:[userbooking]        
        
    }

and it's mongoose model

    booking_date:{
        type: Date,
        default: Date.now,
        required:[true,"Please enter booking date"],
    },
    booking_start:{
        type: Date,
        required:[true,"Please enter booking start"],
    },
    booking_end:{
        type: Date,
        required:[true,"Please enter booking end"]

Please any help would be greatly appreciated

1
  • as this is my first question asked on the site please feel free to let me know if i need to include more information Commented Dec 8, 2022 at 3:28

1 Answer 1

0

okay i figured out what went wrong, the numbers i kept getting back was a timestamp. i had to convert the timestamp into a Date so it could be displayed in the front end properly. if anyone else is having trouble with this here: https://bobbyhadz.com/blog/javascript-convert-milliseconds-to-date hint: if your timestamp is a string use parseInt()

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

Comments

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.