keystonejs/keystone-classic

findOneAndUpdate does not update tracked fields if upserted

Open

#4,442 建立於 2017年9月25日

在 GitHub 查看
 (4 留言) (0 反應) (0 負責人)JavaScript (14,656 star) (2,288 fork)batch import
4.x candidatebughelp wanted

描述

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

貢獻者指南