keystone-classic icon indicating copy to clipboard operation
keystone-classic copied to clipboard

findOneAndUpdate does not update tracked fields if upserted

Open SheaBelsky opened this issue 7 years ago • 4 comments

Expected behavior

Calling findOneAndUpdate and creating a new document (while upsert is set to true) as a result of the function should also update the tracked createdAt and createdBy fields

Actual/Current behavior

It does not update createdAt or createdBy. They are both undefined.

Steps to reproduce the actual/current behavior

  1. Implement a findOneAndUpdate function call on a Keystone model.
  2. Pass it a first argument that represents a document that does not exist.
  3. Pass it a second argument that represents what data the document should have.
  4. Let the function run.
  5. Look at the document in the Admin panel, or retrieve the document some other way.
  6. createdAt and createdBy are both undefined.

I can manually instantiate these fields by passing createdAt and createdBy to the second argument of findOneAndUpdate, but the createdAt date will always update to be whenever the document was updated, rather than being maintained. Using findOneAndUpdate, I've no way of knowing whether this document exists before including this condition.

Environment

Software Version
Keystone 4.0.0-beta.5
Node 6.9.1

SheaBelsky avatar Sep 25 '17 01:09 SheaBelsky

I think this is related to #854, but I don't know if they're the same issue.

SheaBelsky avatar Sep 25 '17 01:09 SheaBelsky

@SHBelsky I think it's the same issue. It still hasn't been implemented. Any chance you can assemble a PR?

Noviny avatar Sep 25 '17 14:09 Noviny

I'll see if I can track down the cause, and make a PR when that happens!

SheaBelsky avatar Sep 27 '17 01:09 SheaBelsky

Having this issue also with the updatedAt field

fergusleen avatar Jan 25 '18 20:01 fergusleen