CosmosDbEx.get_documents

You're seeing just the function get_documents, go back to CosmosDbEx module for more information.
Link to this function

get_documents(container, continuation_token)

View Source

Specs

get_documents(CosmosDbEx.Container.t(), map()) ::
  {:ok
   | :bad_request
   | :conflict
   | :entity_too_large
   | :not_found
   | :storage_limit_reached
   | :unauthorized, CosmosDbEx.Response.t()}

Retrieve all documents in the container. This function defaults to retrieving 100 documents at a time (this is Cosmos Db's default). You can increase the amount of items returned by calling get_documents(container, max_item_count) with any number up to 1000 (Cosmos Dbs max).

If Cosmos Db has more documents than the query returned there will be a Continuation Token present in the properties (has the key continuation_token). You continue retrieving all the documents by using the Continuation Token in your next call to get_documents. See the second example

Examples

iex> CosmosDbEx.Container.new("database", "container") |> CosmosDbEx.get_documents()
{:ok,
 %CosmosDbEx.Response{
  body: %{
    "Documents" => [
      %{
        "_attachments" => "attachments/",
        "_etag" => ""0200c45b-0000-0200-0000-609166640000"",
        "_rid" => "Hj8rAI2HN48BAAAAAAAAAA==",
        "_self" => "dbs/Hj8rAA==/colls/Hj8rAI2HN48=/docs/Hj8rAI2HN48BAAAAAAAAAA==/",
        "_ts" => 1620141668,
        "id" => "d22d663e-6fa1-49af-98f8-df397f266999",
        "name" => "Test item here"
      },
      %{
        "_attachments" => "attachments/",
        "_etag" => ""02003980-0000-0200-0000-60916f6d0000"",
        "_rid" => "Hj8rAI2HN48CAAAAAAAAAA==",
        "_self" => "dbs/Hj8rAA==/colls/Hj8rAI2HN48=/docs/Hj8rAI2HN48CAAAAAAAAAA==/",
        "_ts" => 1620143981,
        "id" => "bef3c1f3-3f66-49a3-ba77-6e8d0e641664",
        "name" => "This is a test"
      }
    ]
  },
  count: 2,
  properties: %{
    continuation_token: nil,
    request_charge: "1",
    request_duration: "0.66"
  },
  resource_id: "Hj8rAI2HN48="
 }
}

iex> container = CosmosDbEx.Container.new("database", "container")
iex> {:ok, response} = container |> CosmosDbEx.get_documents(2)
{:ok,
  %CosmosDbEx.Response{
    body: %{
      "Documents" => [
        %{
          "_attachments" => "attachments/",
          "_etag" => ""0200c45b-0000-0200-0000-609166640000"",
          "_rid" => "Hj8rAI2HN48BAAAAAAAAAA==",
          "_self" => "dbs/Hj8rAA==/colls/Hj8rAI2HN48=/docs/Hj8rAI2HN48BAAAAAAAAAA==/",
          "_ts" => 1620141668,
          "id" => "d22d663e-6fa1-49af-98f8-df397f266999",
          "name" => "Test item here"
        },
        %{
          "_attachments" => "attachments/",
          "_etag" => ""02003980-0000-0200-0000-60916f6d0000"",
          "_rid" => "Hj8rAI2HN48CAAAAAAAAAA==",
          "_self" => "dbs/Hj8rAA==/colls/Hj8rAI2HN48=/docs/Hj8rAI2HN48CAAAAAAAAAA==/",
          "_ts" => 1620143981,
          "id" => "bef3c1f3-3f66-49a3-ba77-6e8d0e641664",
          "name" => "This is a test"
        }
      ]
    },
    count: 2,
    properties: %{
      continuation_token: %{
        "range" => %{"max" => "FF", "min" => ""},
        "token" => "Hj8rAI2HN48CAAAAAAAAAA=="
      },
      request_charge: "1",
      request_duration: "0.429"
    },
    resource_id: "Hj8rAI2HN48="
   }
  }
  iex> {:ok, response} = container |> CosmosDbEx.get_documents(response.properties.continuation_token)
  {:ok,
    %CosmosDbEx.Response{
      body: %{
        "Documents" => [
          %{
            "_attachments" => "attachments/",
            "_etag" => ""82035043-0000-0200-0000-60a1bac30000"",
            "_rid" => "Hj8rAI2HN48DAAAAAAAAAA==",
            "_self" => "dbs/Hj8rAA==/colls/Hj8rAI2HN48=/docs/Hj8rAI2HN48DAAAAAAAAAA==/",
            "_ts" => 1621211843,
            "id" => "2323490-23-23-3923493293",
            "name" => "This is a test of the protocol"
          },
          %{
            "_attachments" => "attachments/",
            "_etag" => ""8203015f-0000-0200-0000-60a1c47e0000"",
            "_rid" => "Hj8rAI2HN48FAAAAAAAAAA==",
            "_self" => "dbs/Hj8rAA==/colls/Hj8rAI2HN48=/docs/Hj8rAI2HN48FAAAAAAAAAA==/",
            "_ts" => 1621214334,
            "id" => "ACME-HD-WOLF01234",
            "location" => "Bottom of a cliff",
            "name" => "ACME hair dryer"
          },
          %{
            "_attachments" => "attachments/",
            "_etag" => ""5d00e34c-0000-0200-0000-60b41c140000"",
            "_rid" => "Hj8rAI2HN48GAAAAAAAAAA==",
            "_self" => "dbs/Hj8rAA==/colls/Hj8rAI2HN48=/docs/Hj8rAI2HN48GAAAAAAAAAA==/",
            "_ts" => 1622416404,
            "id" => "TestDoc-2-1-3-2",
            "location" => "Under da hill",
            "name" => "Just another test document"
          }
        ]
      },
      count: 3,
      properties: %{
        continuation_token: nil,
        request_charge: "1",
        request_duration: "0.596"
      },
      resource_id: "Hj8rAI2HN48="
    }
  }
Link to this function

get_documents(container, max_item_count \\ 100, continuation_token \\ nil)

View Source

Specs

get_documents(CosmosDbEx.Container.t(), integer(), map() | nil) ::
  {:ok
   | :bad_request
   | :conflict
   | :entity_too_large
   | :not_found
   | :storage_limit_reached
   | :unauthorized, CosmosDbEx.Response.t()}