View Source Mongo.BulkOps (mongodb-driver v1.5.0)

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

  1. an atom, which specify the type :insert, :update and :delete
  2. a document or another tuple 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()

Summary

Functions

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

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

Returns an insert_one operation tuple 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.

Types

Functions

@spec 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]}}
@spec get_delete_one(BSON.document()) :: bulk_op()

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

Example

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

{:delete, {%{name: "Waldo"}, [limit: 1]}}
@spec get_insert_one(BSON.document()) :: bulk_op()

Returns an insert_one operation tuple 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
@spec 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
@spec 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
@spec 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]}}