简体   繁体   中英

How to Store Shift Information in Mongo DB

I am migrating from SQL Server to Mongo DB.

In SQLServer, there is a Time datatype to store the Time information only. I use this to store the shift information of an employee.

For example, a regular shift starts at 9:00 AM and ends at 5:00 PM. In SQLServer, I store it as SHIFT_START_TIME(time(7), null) and SHIFT_END_TIME(time(7), null) columns.

Is there a similar way to just store Time information in Mongo ? If not what is the best way ?

MongoDB allows storing of date which include date + time. So either you store time along with date part and ignore date in your code....

But I would suggest following two alternate which I think will be better: 1. Convert time in seconds for example 9:00 AM = 9 * 60 * 60 and for 5:00 PM = (5 + 12) * 60 * 60 2. Store Time as string

In either of the approach you choose you will require to make some changes to your code to handle accordingly...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM