keystonejs/keystone-classic
在 GitHub 查看findOneAndUpdate does not update tracked fields if upserted
Open
#4,442 建立於 2017年9月25日
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
- Implement a
findOneAndUpdatefunction call on a Keystone model. - Pass it a first argument that represents a document that does not exist.
- Pass it a second argument that represents what data the document should have.
- Let the function run.
- Look at the document in the Admin panel, or retrieve the document some other way.
createdAtandcreatedByare bothundefined.
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 |