Mongo.BulkOps (mongodb-driver v0.7.4) View Source

This module defines bulk operation for insert, update and delete. A bulk operation is a tupel of two elements

  1. an atom, which specify the type :insert, :update and :delete
  2. a document or another tupel which contains all parameters of the operation.

You use these function in streams:

Example

alias Mongo.UnorderedBulk
alias Mongo.BulkOps

Filestream!("large.csv")
|> Stream.map(&String.trim(&1))
|> Stream.map(&String.split(&1,","))
|> Stream.map(fn [firstname | [lastname | _]] -> %{firstname: firstname, lastname: lastname} end)
|> Stream.map(fn doc -> BulkOps.get_insert_one(doc) end)
|> UnorderedBulk.write(:mongo, "bulk", 1_000)
|> Stream.run()

Link to this section Summary

Functions

Returns an delete_many operation for appending to a bulk. Used to perform stream bulk writes.

Returns an delete_one operation tupel for appending to a bulk. Used to perform stream bulk writes.

Returns an insert_one operation tupel for appending to a bulk. Used to perform stream bulk writes.

Returns an replace_one operation for appending to a bulk. Used to perform stream bulk writes.

Returns an update_many operation for appending to a bulk. Used to perform stream bulk writes.

Returns an update_one operation for appending to a bulk. Used to perform stream bulk writes.

Link to this section Types

Link to this section Functions

Specs

get_delete_many(BSON.document()) :: bulk_op()

Returns an delete_many operation for appending to a bulk. Used to perform stream bulk writes.

Example

Mongo.BulkOps.get_delete_many(%{name: "Waldo"})

{:delete, {%{name: "Waldo"}, [limit: 0]}}

Specs

get_delete_one(BSON.document()) :: bulk_op()

Returns an delete_one operation tupel for appending to a bulk. Used to perform stream bulk writes.

Example

Mongo.BulkOps.get_delete_one(%{name: "Waldo"})

{:delete, {%{name: "Waldo"}, [limit: 1]}}

Specs

get_insert_one(BSON.document()) :: bulk_op()

Returns an insert_one operation tupel for appending to a bulk. Used to perform stream bulk writes.

Example

Mongo.BulkOps.get_insert_one(%{name: "Waldo"})

{:insert, %{name: "Waldo"}}
Link to this function

get_replace_one(filter, replacement, opts \\ [])

View Source

Specs

get_replace_one(BSON.document(), BSON.document(), Keyword.t()) :: bulk_op()

Returns an replace_one operation for appending to a bulk. Used to perform stream bulk writes.

Example

Mongo.BulkOps.get_replace_one(%{name: "Waldo"}, %{name: "Greta", kind: "dog"})

{:update, {%{name: "Waldo"}, %{kind: "dog", name: "Greta"}, [multi: false]}}
Link to this function

get_update_many(filter, update, opts \\ [])

View Source

Specs

get_update_many(BSON.document(), BSON.document(), Keyword.t()) :: bulk_op()

Returns an update_many operation for appending to a bulk. Used to perform stream bulk writes.

Example

Mongo.BulkOps.get_update_many(%{name: "Waldo"}, %{"$set" : %{name: "Greta", kind: "dog"}})

{:update,
  {%{name: "Waldo"}, %{"$set": %{kind: "dog", name: "Greta"}}, [multi: true]}}
Link to this function

get_update_one(filter, update, opts \\ [])

View Source

Specs

get_update_one(BSON.document(), BSON.document(), Keyword.t()) :: bulk_op()

Returns an update_one operation for appending to a bulk. Used to perform stream bulk writes.

Example
Mongo.BulkOps.get_update_one(%{name: "Waldo"}, %{"$set" : %{name: "Greta", kind: "dog"}})

{:update,
  {%{name: "Waldo"}, %{"$set": %{kind: "dog", name: "Greta"}}, [multi: false]}}