Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Idea: Backfill existing data with creation timestamp #30

Open
pulkitsinghal opened this issue May 18, 2016 · 3 comments
Open

Idea: Backfill existing data with creation timestamp #30

pulkitsinghal opened this issue May 18, 2016 · 3 comments

Comments

@pulkitsinghal
Copy link
Contributor

pulkitsinghal commented May 18, 2016

This got me thinking if the mixin could auto-fill some timestamps for createdAt based on ObjectId ... exciting? see any merit? just ~meh?

@pulkitsinghal
Copy link
Contributor Author

pulkitsinghal commented May 18, 2016

Actually, I don't know if this will fly in your generic mixin which works for both sql and nosql but where would be a good place to handle upserts for mongo in your mixin with $currentDate and $setOnInsert so that folks don't have to worry about that stuff?

@clarkbw
Copy link
Owner

clarkbw commented May 19, 2016

handle upserts for mongo in your mixin with $currentDate and $setOnInsert

💯 That might be a nice way to handle the upsert problem. In the generic sense there's no easy way unless query the database for the values before completing the upsert, something that invalidates the value of an upsert. However if those values were available without a query round trip and were the correct values to use I think it would make sense to create a shim.

I haven't done any investigation on this, so assuming those values are the right ones. I would probably create the following structure.

db.js
db/mongodb.js

Where the db.js file does the detection of the currently used database and provides either the mono module or no-op functions for other currently unsupported dbs; likely passing it the Model.

The monogodb file would probably just have one method exported, something like lookup which takes the ctx.instance (I don't think ctx.data would work) and adds the proper fields that would allow for an upsert with validation.

@pulkitsinghal
Copy link
Contributor Author

I'm still digesting your input ... in the meantime this snapshot represents the simplest set of from/to changes to get it done in code if the mixin doesn't take care of it, hoping to apply it to the mixin somehow.

screenshot 2016-05-19 10 56 52

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

No branches or pull requests

2 participants