I don't see my previous collections after adding in versions

default discord avatar
nh02.
5 months ago
6

I added drafts to my pageType collection, however afterwards the pages I already made in this collection didn't show anymore in the admin/collection/pageType. Below is my code I added. Does anyone know If I'm missing something?



access: {
    read: () => {
      if (isLoggedIn) {
        return true;
      }

      return {
        or: [
          {
            _status: {
              equals: 'published',
            },
          },
          {
            _status: {
              exists: false,
            },
          },
        ],
      };
    },
  },
  versions: {
    drafts: true,
  },
  • discord user avatar
    dribbens
    Payload Team
    5 months ago

    What happens is the list is populated from querying from _collectionname_versions, a separate collection from the main when versions are enabled. To fix it, every document that existed before versions was enabled needs to be resaved.


    There is a script in the changelog that resaves all documents in a collection. It could also be done using a PATCH request for the entire collection.



    PATCH


    /api/pageType?where[id][exists]=true


    body: {_status: 'draft'}


    headers: {


    content-type: application/json


    authorization: JWT TOKENFROMCOOKIE


    }



    Sorry for the psuedocode, I'm on mobile. I hope this gives you an idea on what to do.


    This is something we need to document better.

  • default discord avatar
    nh02.
    5 months ago

    Cool! Thanks for the quick response!

  • default discord avatar
    xgzepto
    last month

    Hey, just asking if adding _status solves your issue; I tried adding this directly to the database and the problem persists 😢

  • default discord avatar
    yageee
    last month

    Can you share the script for resave all documents in a collection, please?



    btw, thanks for the PATCH example, works well!

  • default discord avatar
    nh02.
    last month

    Apologies for the late response. If it's still relevavant to you, adding _status wasn't the way to go, but instead running the migrateVersions script available on payloads github repo.

  • default discord avatar
    xgzepto
    last month

    thx for the reply 🫡 problem solved

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.