Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Dynamic Dates - Defining Dates with Dynamic Field Names #2446

Open
danhanly opened this issue Sep 15, 2022 · 1 comment
Open

Comments

@danhanly
Copy link

Is your feature request related to a problem?

I have a problem where I'm attempting to add a bunch of dates to user-supplied field-names. As an example, think of them like custom tags with a timestamp attached. So every field within this nested relationship will be a date, as in the below structure:

Blog Post
    | -> ID = 1
    | -> Tags
             | -> Tag Name = Timestamp
             | -> Tag Name = Timestamp
             | -> ...

At present, I'm not sure if there's a way for me to ensure that the Carbon dates I work with in the logic are able to be inserted as a MongoDB Timestamp, since the only facility for managing dates is the presence of the $date property on the model, which as far as I'm aware, doesn't accept wildcards.

So my insert code requires a manual conversion to the \MongoDb\BSON\UTCDateTime class.

Given the flexible nature of Mongo with fields able to be added ad-hoc, it stands to reason that the rules that define those fields could be more flexible too.

Describe the solution you'd like

Some way to define wildcards, or regex within the $dates property, so that I can ensure that any date that matches a particular pattern is added converted to and from the appropriate date classes at the appropriate times.

Describe alternatives you've considered

At the moment, if I want to use these dynamic fields in an insert logic, or in a where logic, I must convert the Carbon/Datetime class to \MongoDb\BSON\UTCDateTime, so I'm not currently prevented from doing this, but the method feels messy and unintegrated.

Additional context

My use case is specific, but there is more I can think of, especially with accountability with our users about when certain features or systems were added to their account.

@Iscrimou
Copy link

I have a problem with dynamic timestamp using this package, and "\MongoDb\BSON\UTCDateTime" doesn't exist for me, I'm actually using "jenssegers/mongodb": "^3.9", and "mongodb/mongodb": "^1.12"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants