This guide covers:
This work is licensed under a Creative Commons Attribution 3.0 Unported License (including images & stylesheets). The source is available on Github.
This guide covers Monger 3.1 (including preview releases).
Documents are removed using monger.collection/remove
function that
takes a collection name and conditions:
(ns my.service.server
(:require [monger.core :as mg]
[monger.collection :as mc])
(:import [org.bson.types.ObjectId]))
(let [conn (mg/connect)
db (mg/get-db conn "monger-test")
coll "documents"]
;; insert a few documents
(mc/insert db coll { :language "English" :pages 38 })
(mc/insert db coll { :language "Spanish" :pages 78 })
(mc/insert db coll { :language "Unknown" :pages 87 })
;; remove multiple documents
(mc/remove db coll { :language "English" })
;; remove ALL documents in the collection
(mc/remove db coll))
monger.collection/remove-by-id
is useful when document id is known:
(ns my.service.server
(:require [monger.core :as mg]
[monger.collection :as mc])
(:import org.bson.types.ObjectId))
(let [conn (mg/connect)
db (mg/get-db conn "monger-test")
coll "documents"]
;; remove document by id
(let [oid (ObjectId.)]
(mc/insert db coll { :language "English" :pages 38 :_id oid })
(mc/remove-by-id db coll oid)))
The documentation is organized as a number of guides, covering all kinds of topics.
We recommend that you read the following guides first, if possible, in this order:
Please take a moment to tell us what you think about this guide on Twitter or the Monger mailing list
Let us know what was unclear or what has not been covered. Maybe you do not like the guide style or grammar or discover spelling mistakes. Reader feedback is key to making the documentation better.