rmongodb (version 1.8.0)

mongo.remove: Remove records from a collection

Description

Remove all records from a collection that match a given criteria.

Usage

mongo.remove(mongo, ns, criteria = mongo.bson.empty())

Arguments

mongo
(mongo) a mongo connection object.
ns
(string) namespace of the collection from which to remove records.
criteria
(mongo.bson) The criteria with which to match records that are to be removed. The default of mongo.bson.empty() will cause all records in the given collection to be removed.

Alternately, criteria may be a list which will be converted to a mongo.bson object by mongo.bson.from.list().

Alternately, criteria may be a valid JSON character string which will be converted to a mongo.bson object by mongo.bson.from.JSON().

Details

See http://www.mongodb.org/display/DOCS/Removing.

See Also

mongo, mongo.bson, mongo.insert, mongo.update, mongo.find, mongo.find.one.

Examples

Run this code
mongo <- mongo.create()
if (mongo.is.connected(mongo)) {
    buf <- mongo.bson.buffer.create()
    mongo.bson.buffer.append(buf, "name", "Jeff")
    criteria <- mongo.bson.from.buffer(buf)

    # remove all records where name is "Jeff"
    # from collection people in database test
    mongo.remove(mongo, "test.people", criteria)

    # remove all records from collection cars in database test
    mongo.remove(mongo, "test.cars")

    # shorthand: remove all records where name is "Fred"
    mongo.remove(mongo, "test.people", list(name="Fred"))
}

Run the code above in your browser using DataLab