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 1.6 (including beta releases).
Documents are removed using monger.collection/remove function that takes a collection name and conditions:
(ns my.service.server
(:require [monger.collection :as mc])
(:use [monger.core :only [connect! connect set-db! get-db]])
(:import [org.bson.types ObjectId]))
;; localhost, default port
(connect!)
(set-db! (monger.core/get-db "monger-test"))
;; insert a few documents
(mc/insert "documents" { :language "English" :pages 38 })
(mc/insert "documents" { :language "Spanish" :pages 78 })
(mc/insert "documents" { :language "Unknown" :pages 87 })
;; remove multiple documents
(mc/remove "documents" { :language "English" })
;; remove ALL documents in the collection
(mc/remove "documents")
monger.collection/remove-by-id is useful when document id is known:
(ns my.service.server
(:use [monger.core :only [connect! connect set-db! get-db]]
[monger.collection :only [insert remove-by-id] :as mc])
(:import [org.bson.types ObjectId]))
;; localhost, default port
(connect!)
(set-db! (monger.core/get-db "monger-test"))
;; remove document by id
(let [oid (ObjectId.)]
(insert "documents" { :language "English" :pages 38 :_id oid })
(remove-by-id "documents" 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.