Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

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

default discord avatar
nh02.last year
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
    last year

    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.last year

    Cool! Thanks for the quick response!

  • default discord avatar
    xgzeptolast year

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

  • default discord avatar
    yageeelast year

    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 year

    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
    xgzeptolast year

    thx for the reply 🫡 problem solved

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

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