Importing / Parsing a CSV into a collection

default discord avatar
nicolaslair
6 months ago
7

Hi there, anyone already done a CVS import to pre-populate a collection? Thanks in advance #community-help

  • default discord avatar
    notchr
    6 months ago

    Hello @nicolaslair - I've heard of people doing this, there may even be a code example in the discord archive



    However, you could create a script to loop over each entry in your CSV and hit the create endpoint for that collection



    You could also do it via a migration script in mongodb, but the API route feels easier to me

  • default discord avatar
    nicolaslair
    6 months ago

    Thanks @notchr - do you think it would be a good use case for a plugin?

  • default discord avatar
    notchr
    6 months ago

    @Ab



    @nicolaslair It could be if enough people are importing a lot of data!

  • discord user avatar
    denolfe
    Payload Team
    6 months ago

    @nicolaslair Here's an example script doing an import from csv

    https://payloadcms.com/community-help/github/user-csv-import-for-a-collection
  • default discord avatar
    nicolaslair
    6 months ago

    Thanks a lot Elliot - I actually ended up writing a complete DB seed script using Payload in 'local' mode - really handy feature 👍

  • default discord avatar
    ssyberg
    4 months ago

    Just a word of warning for anyone who ends up here, there's some divergence between data operations between dashboard and local API and this can lead to some pretty difficult to diagnose bugs on programmatic data interactions - two discussions in GH:

    https://github.com/payloadcms/payload/discussions/2889

    and

    https://github.com/payloadcms/payload/discussions/2785
  • default discord avatar
    altered.coder
    last month

    @nicolaslair @denolfe I am using

    next-payload

    and want to give user the option to upload bulk data in a collection, how can I achieve that..?



    This option won't work for me, I need to do it using hooks or something, any help about that..?

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.