Skip to content

Collection table data not showing updated when editing mongo directly #4501

Closed

Description

@ericuldall

Link to reproduction

No response

Describe the Bug

I have a query in an order collection that changes my stock for inventory items using $inc

              const inventory = payload.db.collections.inventory
              await inventory.findByIdAndUpdate(
                inventoryItem.id,
                {
                  $inc: { stock: quantityDiff }
                }, {
                  new: true
                }
              ).exec();

The fields are updated correctly when looking at the edit form for that collection item, but the data is showing the previous value when looking at the list of collection items.

Is there some extra step I need to take to fully commit that change?

To Reproduce

Enable versions, then edit mongo data directly.

Payload Version

2

Adapters and Plugins

No response

Activity

  1. DanRibbens commented on Dec 13, 2023

    @DanRibbens
    Contributor

    Okay, since you mentioned you have versions enabled, I know what is going on.

    The list view is displayed by querying a secondary collection that is named from your collection slug, prefixed with _versions_, so _inventory_versions in your case. Only published documents end up in the natural db collection and this is not the data that is used in the list view.

    You might want to update inventory using the Paylaod local API, you will have to read and update the document to increment the stock in code. The upside is that your versions will be updated in the database as one might expect.

    If you don't care about maintaining the version history of the stock value specifically, you could maintain both collections versions and collection how you have done it. You can access the latest version for a document by querying on the latest: {$eq: true} and you can get the version collection from: payload.db.versions.inventory.

    I am going to convert this issue to a discussion since there isn't anything to fix at this time.

  2. locked and limited conversation to collaborators on Dec 13, 2023
  3. converted this issue into a discussion #4503 on Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: needs-triagePossible bug which hasn't been reproduced yet

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions