Bulk_create - getting (UndefinedFunctionError) function Ash.Api.bulk_create/4

I have to seed a City resource with some 9,000 cities. I thought bulk_create would be the best way of doing it. I don’t understand the syntax in the docs.

I always get the error:

** (UndefinedFunctionError) function Ash.Api.bulk_create/4 is undefined or private. Did you mean:

      * bulk_create/5

Here is what I am trying:

  def seed_cities() do
    cities()
    |> Ash.Api.bulk_create(Animina.GeoData.City, :create, 
return_stream?: true, return_records?: true, batch_size: 100)
  end

  defp cities do
    [
      %{
        lat: 48.6636692435,
        lon: 11.9427079587,
        county: "Landkreis Landshut",
        federal_state: "Bayern",
        zip_code: "84076",
        name: "Pfeffenhausen"
      },
      %{
        lat: 49.1048954964,
        lon: 11.9815273794,
        county: "Landkreis Regensburg",
        federal_state: "Bayern",
        zip_code: "93195",
        name: "Wolfsegg"
      }
]
end

You still need to use the API module you defined.

e.g. Animina.GeoData.Api

I tried this:

  defp seed_cities() do
    cities()
    |> Animina.GeoData.Api.bulk_create(Animina.GeoData.City, :create, return_stream?: true, return_records?: true, batch_size: 10)
  end

But still get an error:

** (UndefinedFunctionError) function Animina.GeoData.Api.bulk_create/4 is undefined (module Animina.GeoData.Api is not available)

What is your api module called?

1 Like

Ah! Thanks!

This did the trick:

Animina.GeoData.bulk_create(Animina.GeoData.City, :create,
      return_stream?: false,
      return_records?: false,
      batch_size: 100
    )
1 Like