public abstract class

DBCollection

extends Object
java.lang.Object
   ↳ com.mongodb.DBCollection

Class Overview

This class provides a skeleton implementation of a database collection.

A typical invocation sequence is thus

     Mongo mongo = new Mongo( new DBAddress( "localhost", 127017 ) );
     DB db = mongo.getDB( "mydb" );
     DBCollection collection = db.getCollection( "test" );
 

Summary

Fields
protected final String _fullName
protected List<DBObject> _hintFields
protected final String _name
protected Class _objectClass
Protected Constructors
DBCollection(DB base, String name)
Initializes a new collection.
Public Methods
void addOption(int option)
adds a default query option
Object apply(DBObject o)
calls apply(com.mongodb.DBObject, boolean) with ensureID=true
Object apply(DBObject jo, boolean ensureID)
calls doapply(com.mongodb.DBObject), optionally adding an automatic _id field
long count(DBObject query)
returns the number of documents that match a query.@return
long count()
returns the number of documents in this collection.@return
abstract void createIndex(DBObject keys, DBObject options, DBEncoder encoder)
Forces creation of an index on a set of fields, if one does not already exist.
void createIndex(DBObject keys)
void createIndex(DBObject keys, DBObject options)
Forces creation of an index on a set of fields, if one does not already exist.
List distinct(String key, DBObject query)
find distinct values for a key
List distinct(String key)
find distinct values for a key
void drop()
Drops (deletes) this collection.
void dropIndex(String name)
Drops an index from this collection
void dropIndex(DBObject keys)
Drops an index from this collection
void dropIndexes(String name)
Drops an index from this collection
void dropIndexes()
Drops all indices from this collection
void ensureIndex(DBObject keys, String name, boolean unique)
Ensures an index on this collection (that is, the index will be created if it does not exist).
void ensureIndex(DBObject keys)
void ensureIndex(DBObject keys, String name)
void ensureIndex(String name)
Creates an ascending index on a field with default options, if one does not already exist.
void ensureIndex(DBObject keys, DBObject optionsIN)
Creates an index on a set of fields, if one does not already exist.
boolean equals(Object o)
DBCursor find(DBObject query, DBObject fields, int numToSkip, int batchSize)
Finds objects from the database that match a query.
DBCursor find(DBObject ref)
Queries for an object in this collection.
DBCursor find()
Queries for all objects in this collection.
DBCursor find(DBObject query, DBObject fields, int numToSkip, int batchSize, int options)
DBCursor find(DBObject ref, DBObject keys)
Queries for an object in this collection.
DBObject findAndModify(DBObject query, DBObject fields, DBObject sort, boolean remove, DBObject update, boolean returnNew, boolean upsert)
Finds the first document in the query and updates it.
DBObject findAndModify(DBObject query, DBObject sort, DBObject update)
DBObject findAndModify(DBObject query, DBObject update)
DBObject findAndRemove(DBObject query)
DBObject findOne(Object obj, DBObject fields)
Finds an object by its id.
DBObject findOne(DBObject o)
Returns a single object from this collection matching the query.
DBObject findOne(Object obj)
Finds an object by its id.
DBObject findOne(DBObject o, DBObject fields, ReadPreference readPref)
Returns a single object from this collection matching the query.
DBObject findOne(DBObject o, DBObject fields)
Returns a single object from this collection matching the query.
DBObject findOne()
Returns a single object from this collection.
static String genIndexName(DBObject keys)
Convenience method to generate an index name from the set of fields it is over.
DBCollection getCollection(String n)
Finds a collection that is prefixed with this collection's name.
long getCount(DBObject query)
long getCount(DBObject query, DBObject fields, long limit, long skip)
Returns the number of documents in the collection that match the specified query
long getCount(DBObject query, DBObject fields)
long getCount()
calls getCount(com.mongodb.DBObject, com.mongodb.DBObject) with an empty query and null fields.
DB getDB()
Returns the database this collection is a member of.
synchronized DBDecoderFactory getDBDecoderFactory()
Get the decoder factory for this collection.
synchronized DBEncoderFactory getDBEncoderFactory()
Get the encoder factory for this collection.
String getFullName()
Returns the full name of this collection, with the database name as a prefix.
List<DBObject> getIndexInfo()
Return a list of the indexes for this collection.
String getName()
Returns the name of this collection.
Class getObjectClass()
Gets the default class for objects in the collection
int getOptions()
gets the default query options
ReadPreference getReadPreference()
Gets the read preference
CommandResult getStats()
gets the collections statistics ("collstats" command)
WriteConcern getWriteConcern()
Get the write concern for this collection.
DBObject group(DBObject args)
This method is deprecated. prefer the group(com.mongodb.GroupCommand) which is more standard Applies a group operation
DBObject group(GroupCommand cmd)
Applies a group operation@return
DBObject group(DBObject key, DBObject cond, DBObject initial, String reduce)
DBObject group(DBObject key, DBObject cond, DBObject initial, String reduce, String finalize)
Applies a group operation@return
int hashCode()
WriteResult insert(WriteConcern concern, DBObject... arr)
Saves document(s) to the database.
WriteResult insert(List<DBObject> list, WriteConcern concern)
Saves document(s) to the database.
WriteResult insert(DBObject... arr)
Saves document(s) to the database.
WriteResult insert(DBObject[] arr, WriteConcern concern)
Saves document(s) to the database.
WriteResult insert(List<DBObject> list)
Saves document(s) to the database.
abstract WriteResult insert(DBObject[] arr, WriteConcern concern, DBEncoder encoder)
Saves document(s) to the database.
WriteResult insert(DBObject o, WriteConcern concern)
Inserts a document into the database.
boolean isCapped()
returns whether or not this is a capped collection
MapReduceOutput mapReduce(String map, String reduce, String outputTarget, MapReduceCommand.OutputType outputType, DBObject query)
performs a map reduce operation Specify an outputType to control job execution * INLINE - Return results inline * REPLACE - Replace the output collection with the job output * MERGE - Merge the job output with the existing contents of outputTarget * REDUCE - Reduce the job output with the existing contents of outputTarget@return
MapReduceOutput mapReduce(DBObject command)
performs a map reduce operation@return
MapReduceOutput mapReduce(String map, String reduce, String outputTarget, DBObject query)
performs a map reduce operation Runs the command in REPLACE output mode (saves to named collection)@return
MapReduceOutput mapReduce(MapReduceCommand command)
performs a map reduce operation@return
abstract WriteResult remove(DBObject o, WriteConcern concern, DBEncoder encoder)
Removes objects from the database collection.@return
WriteResult remove(DBObject o)
calls remove(com.mongodb.DBObject, com.mongodb.WriteConcern) with the default WriteConcern@return
WriteResult remove(DBObject o, WriteConcern concern)
Removes objects from the database collection.@return
DBCollection rename(String newName)
Calls rename(java.lang.String, boolean) with dropTarget=false
DBCollection rename(String newName, boolean dropTarget)
renames of this collection to newName
void resetIndexCache()
Clears all indices that have not yet been applied to this collection.
void resetOptions()
resets the default query options
WriteResult save(DBObject jo, WriteConcern concern)
Saves an object to this collection (does insert or update based on the object _id).@return
WriteResult save(DBObject jo)
synchronized void setDBDecoderFactory(DBDecoderFactory fact)
Set a customer decoder factory for this collection.
synchronized void setDBEncoderFactory(DBEncoderFactory fact)
Set a customer encoder factory for this collection.
void setHintFields(List<DBObject> lst)
Set hint fields for this collection (to optimize queries).
void setInternalClass(String path, Class c)
sets the internal class
void setObjectClass(Class c)
Sets a default class for objects in this collection; null resets the class to nothing.
void setOptions(int options)
sets the default query options
void setReadPreference(ReadPreference preference)
Sets the read preference for this collection.
void setWriteConcern(WriteConcern concern)
Set the write concern for this collection.
void slaveOk()
This method is deprecated. Replaced with ReadPreference.SECONDARY
String toString()
abstract WriteResult update(DBObject q, DBObject o, boolean upsert, boolean multi, WriteConcern concern, DBEncoder encoder)
Performs an update operation.@return
WriteResult update(DBObject q, DBObject o, boolean upsert, boolean multi, WriteConcern concern)
Performs an update operation.@return
WriteResult update(DBObject q, DBObject o)
calls update(com.mongodb.DBObject, com.mongodb.DBObject, boolean, boolean) with upsert=false and multi=false@return
WriteResult update(DBObject q, DBObject o, boolean upsert, boolean multi)
WriteResult updateMulti(DBObject q, DBObject o)
calls update(com.mongodb.DBObject, com.mongodb.DBObject, boolean, boolean) with upsert=false and multi=true@return
Protected Methods
DBObject _checkObject(DBObject o, boolean canBeNull, boolean query)
boolean checkReadOnly(boolean strict)
Returns if this collection's database is read-only
abstract void doapply(DBObject o)
Adds any necessary fields to a given object before saving it to the collection.
Class getInternalClass(String path)
gets the internal class
[Expand]
Inherited Methods
From class java.lang.Object

Fields

protected final String _fullName

protected List<DBObject> _hintFields

protected final String _name

protected Class _objectClass

Protected Constructors

protected DBCollection (DB base, String name)

Initializes a new collection. No operation is actually performed on the database.

Parameters
base database in which to create the collection
name the name of the collection

Public Methods

public void addOption (int option)

adds a default query option

public Object apply (DBObject o)

calls apply(com.mongodb.DBObject, boolean) with ensureID=true

Parameters
o DBObject to which to add fields
Returns
  • the modified parameter object

public Object apply (DBObject jo, boolean ensureID)

calls doapply(com.mongodb.DBObject), optionally adding an automatic _id field

Parameters
jo object to add fields to
ensureID whether to add an _id field
Returns
  • the modified object o

public long count (DBObject query)

returns the number of documents that match a query.@return

Parameters
query query to match

public long count ()

returns the number of documents in this collection.@return

public abstract void createIndex (DBObject keys, DBObject options, DBEncoder encoder)

Forces creation of an index on a set of fields, if one does not already exist.

Parameters
encoder the DBEncoder to use

public void createIndex (DBObject keys)

Parameters
keys an object with a key set of the fields desired for the index

public void createIndex (DBObject keys, DBObject options)

Forces creation of an index on a set of fields, if one does not already exist.

public List distinct (String key, DBObject query)

find distinct values for a key

Parameters
query query to match

public List distinct (String key)

find distinct values for a key

public void drop ()

Drops (deletes) this collection. Use with care.

public void dropIndex (String name)

Drops an index from this collection

Parameters
name name of index to drop

public void dropIndex (DBObject keys)

Drops an index from this collection

Parameters
keys keys of the index

public void dropIndexes (String name)

Drops an index from this collection

Parameters
name the index name

public void dropIndexes ()

Drops all indices from this collection

public void ensureIndex (DBObject keys, String name, boolean unique)

Ensures an index on this collection (that is, the index will be created if it does not exist).

Parameters
keys fields to use for index
name an identifier for the index. If null or empty, the default name will be used.
unique if the index should be unique

public void ensureIndex (DBObject keys)

Parameters
keys an object with a key set of the fields desired for the index

public void ensureIndex (DBObject keys, String name)

Parameters
keys fields to use for index
name an identifier for the index
Throws
MongoException
MongoException

public void ensureIndex (String name)

Creates an ascending index on a field with default options, if one does not already exist.

Parameters
name name of field to index on

public void ensureIndex (DBObject keys, DBObject optionsIN)

Creates an index on a set of fields, if one does not already exist.

Parameters
keys an object with a key set of the fields desired for the index
optionsIN options for the index (name, unique, etc)

public boolean equals (Object o)

public DBCursor find (DBObject query, DBObject fields, int numToSkip, int batchSize)

Finds objects from the database that match a query. A DBCursor object is returned, that can be iterated to go through the results.

Parameters
query query used to search
fields the fields of matching objects to return
numToSkip number of objects to skip
batchSize the batch size. This option has a complex behavior, see batchSize(int)
Returns
  • the cursor
Throws
MongoException

public DBCursor find (DBObject ref)

Queries for an object in this collection.

Parameters
ref object for which to search
Returns
  • an iterator over the results

public DBCursor find ()

Queries for all objects in this collection.

Returns
  • a cursor which will iterate over every object

public DBCursor find (DBObject query, DBObject fields, int numToSkip, int batchSize, int options)

Parameters
query query used to search
fields the fields of matching objects to return
numToSkip number of objects to skip
batchSize the batch size. This option has a complex behavior, see batchSize(int)
options - see Bytes QUERYOPTION_*
Returns
  • the cursor
Throws
MongoException
MongoException

public DBCursor find (DBObject ref, DBObject keys)

Queries for an object in this collection.

An empty DBObject will match every document in the collection. Regardless of fields specified, the _id fields are always returned.

An example that returns the "x" and "_id" fields for every document in the collection that has an "x" field:

 BasicDBObject keys = new BasicDBObject();
 keys.put("x", 1);

 DBCursor cursor = collection.find(new BasicDBObject(), keys);
 

Parameters
ref object for which to search
keys fields to return
Returns
  • a cursor to iterate over results

public DBObject findAndModify (DBObject query, DBObject fields, DBObject sort, boolean remove, DBObject update, boolean returnNew, boolean upsert)

Finds the first document in the query and updates it.

Parameters
query query to match
fields fields to be returned
sort sort to apply before picking first document
remove if true, document found will be removed
update update to apply
returnNew if true, the updated document is returned, otherwise the old document is returned (or it would be lost forever)
upsert do upsert (insert if document not present)
Returns
  • the document

public DBObject findAndModify (DBObject query, DBObject sort, DBObject update)

Returns
  • the old document

public DBObject findAndModify (DBObject query, DBObject update)

Returns
  • the old document

public DBObject findAndRemove (DBObject query)

Returns
  • the removed document

public DBObject findOne (Object obj, DBObject fields)

Finds an object by its id. This compares the passed in value to the _id field of the document

Parameters
obj any valid object
fields fields to return
Returns
  • the object, if found, otherwise null

public DBObject findOne (DBObject o)

Returns a single object from this collection matching the query.

Parameters
o the query object
Returns
  • the object found, or null if no such object exists

public DBObject findOne (Object obj)

Finds an object by its id. This compares the passed in value to the _id field of the document

Parameters
obj any valid object
Returns
  • the object, if found, otherwise null

public DBObject findOne (DBObject o, DBObject fields, ReadPreference readPref)

Returns a single object from this collection matching the query.

Parameters
o the query object
fields fields to return
Returns
  • the object found, or null if no such object exists

public DBObject findOne (DBObject o, DBObject fields)

Returns a single object from this collection matching the query.

Parameters
o the query object
fields fields to return
Returns
  • the object found, or null if no such object exists

public DBObject findOne ()

Returns a single object from this collection.

Returns
  • the object found, or null if the collection is empty

public static String genIndexName (DBObject keys)

Convenience method to generate an index name from the set of fields it is over.

Parameters
keys the names of the fields used in this index
Returns
  • a string representation of this index's fields

public DBCollection getCollection (String n)

Finds a collection that is prefixed with this collection's name. A typical use of this might be

    DBCollection users = mongo.getCollection( "wiki" ).getCollection( "users" );
 
Which is equivalent to
DBCollection users = mongo.getCollection( "wiki.users" );

Parameters
n the name of the collection to find
Returns
  • the matching collection

public long getCount (DBObject query)

Parameters
query query to match

public long getCount (DBObject query, DBObject fields, long limit, long skip)

Returns the number of documents in the collection that match the specified query

Parameters
query query to select documents to count
fields fields to return
limit limit the count to this value
skip number of entries to skip
Returns
  • number of documents that match query and fields

public long getCount (DBObject query, DBObject fields)

Parameters
query query to match
fields fields to return

public long getCount ()

calls getCount(com.mongodb.DBObject, com.mongodb.DBObject) with an empty query and null fields.

Returns
  • number of documents that match query

public DB getDB ()

Returns the database this collection is a member of.

Returns
  • this collection's database

public synchronized DBDecoderFactory getDBDecoderFactory ()

Get the decoder factory for this collection. A null return value means that the default from MongoOptions is being used.

Returns
  • the factory

public synchronized DBEncoderFactory getDBEncoderFactory ()

Get the encoder factory for this collection. A null return value means that the default from MongoOptions is being used.

Returns
  • the factory

public String getFullName ()

Returns the full name of this collection, with the database name as a prefix.

Returns
  • the name of this collection

public List<DBObject> getIndexInfo ()

Return a list of the indexes for this collection. Each object in the list is the "info document" from MongoDB

Returns
  • list of index documents

public String getName ()

Returns the name of this collection.

Returns
  • the name of this collection

public Class getObjectClass ()

Gets the default class for objects in the collection

Returns
  • the class

public int getOptions ()

gets the default query options

public ReadPreference getReadPreference ()

Gets the read preference

public CommandResult getStats ()

gets the collections statistics ("collstats" command)

public WriteConcern getWriteConcern ()

Get the write concern for this collection.

public DBObject group (DBObject args)

This method is deprecated.
prefer the group(com.mongodb.GroupCommand) which is more standard Applies a group operation

@return

Parameters
args object representing the arguments to the group function
Throws
MongoException
MongoException

public DBObject group (GroupCommand cmd)

Applies a group operation@return

Parameters
cmd the group command
Throws
MongoException

public DBObject group (DBObject key, DBObject cond, DBObject initial, String reduce)

Parameters
key - { a : true }
cond - optional condition on query
initial initial value for first match on a key
reduce javascript reduce function
Throws
MongoException
MongoException

public DBObject group (DBObject key, DBObject cond, DBObject initial, String reduce, String finalize)

Applies a group operation@return

Parameters
key - { a : true }
cond - optional condition on query
initial initial value for first match on a key
reduce javascript reduce function
finalize An optional function that can operate on the result(s) of the reduce function.
Throws
MongoException
MongoException

public int hashCode ()

public WriteResult insert (WriteConcern concern, DBObject... arr)

Saves document(s) to the database. if doc doesn't have an _id, one will be added you can get the _id that was added from doc after the insert@return

Parameters
arr array of documents to save
Throws
MongoException
MongoException

public WriteResult insert (List<DBObject> list, WriteConcern concern)

Saves document(s) to the database. if doc doesn't have an _id, one will be added you can get the _id that was added from doc after the insert@return

Parameters
list list of documents to save
concern the write concern
Throws
MongoException
MongoException

public WriteResult insert (DBObject... arr)

Saves document(s) to the database. if doc doesn't have an _id, one will be added you can get the _id that was added from doc after the insert@return

Parameters
arr array of documents to save
Throws
MongoException
MongoException

public WriteResult insert (DBObject[] arr, WriteConcern concern)

Saves document(s) to the database. if doc doesn't have an _id, one will be added you can get the _id that was added from doc after the insert@return

Parameters
arr array of documents to save
concern the write concern
Throws
MongoException
MongoException

public WriteResult insert (List<DBObject> list)

Saves document(s) to the database. if doc doesn't have an _id, one will be added you can get the _id that was added from doc after the insert@return

Parameters
list list of documents to save
Throws
MongoException
MongoException

public abstract WriteResult insert (DBObject[] arr, WriteConcern concern, DBEncoder encoder)

Saves document(s) to the database. if doc doesn't have an _id, one will be added you can get the _id that was added from doc after the insert@return

Parameters
arr array of documents to save
concern the write concern
encoder the DBEncoder to use
Throws
MongoException
MongoException

public WriteResult insert (DBObject o, WriteConcern concern)

Inserts a document into the database. if doc doesn't have an _id, one will be added you can get the _id that was added from doc after the insert@return

Parameters
concern the write concern
Throws
MongoException
MongoException

public boolean isCapped ()

returns whether or not this is a capped collection

public MapReduceOutput mapReduce (String map, String reduce, String outputTarget, MapReduceCommand.OutputType outputType, DBObject query)

performs a map reduce operation Specify an outputType to control job execution * INLINE - Return results inline * REPLACE - Replace the output collection with the job output * MERGE - Merge the job output with the existing contents of outputTarget * REDUCE - Reduce the job output with the existing contents of outputTarget@return

Parameters
map map function in javascript code
reduce reduce function in javascript code
outputTarget optional - leave null if want to use temp collection
outputType set the type of job output
query to match
Throws
MongoException
MongoException

public MapReduceOutput mapReduce (DBObject command)

performs a map reduce operation@return

Parameters
command object representing the parameters

public MapReduceOutput mapReduce (String map, String reduce, String outputTarget, DBObject query)

performs a map reduce operation Runs the command in REPLACE output mode (saves to named collection)@return

Parameters
map map function in javascript code
reduce reduce function in javascript code
outputTarget optional - leave null if want to use temp collection
query to match
Throws
MongoException
MongoException

public MapReduceOutput mapReduce (MapReduceCommand command)

performs a map reduce operation@return

Parameters
command object representing the parameters

public abstract WriteResult remove (DBObject o, WriteConcern concern, DBEncoder encoder)

Removes objects from the database collection.@return

Parameters
o the object that documents to be removed must match
concern WriteConcern for this operation
encoder the DBEncoder to use
Throws
MongoException
MongoException

public WriteResult remove (DBObject o)

calls remove(com.mongodb.DBObject, com.mongodb.WriteConcern) with the default WriteConcern@return

Parameters
o the object that documents to be removed must match
Throws
MongoException
MongoException

public WriteResult remove (DBObject o, WriteConcern concern)

Removes objects from the database collection.@return

Parameters
o the object that documents to be removed must match
concern WriteConcern for this operation
Throws
MongoException
MongoException

public DBCollection rename (String newName)

Calls rename(java.lang.String, boolean) with dropTarget=false

Parameters
newName new collection name (not a full namespace)
Returns
  • the new collection

public DBCollection rename (String newName, boolean dropTarget)

renames of this collection to newName

Parameters
newName new collection name (not a full namespace)
dropTarget if a collection with the new name exists, whether or not to drop it
Returns
  • the new collection

public void resetIndexCache ()

Clears all indices that have not yet been applied to this collection.

public void resetOptions ()

resets the default query options

public WriteResult save (DBObject jo, WriteConcern concern)

Saves an object to this collection (does insert or update based on the object _id).@return

Parameters
jo the DBObject to save
concern the write concern

public WriteResult save (DBObject jo)

Parameters
jo the DBObject to save will add _id field to jo if needed

public synchronized void setDBDecoderFactory (DBDecoderFactory fact)

Set a customer decoder factory for this collection. Set to null to use the default from MongoOptions.

Parameters
fact the factory to set.

public synchronized void setDBEncoderFactory (DBEncoderFactory fact)

Set a customer encoder factory for this collection. Set to null to use the default from MongoOptions.

Parameters
fact the factory to set.

public void setHintFields (List<DBObject> lst)

Set hint fields for this collection (to optimize queries).

Parameters
lst a list of DBObjects to be used as hints

public void setInternalClass (String path, Class c)

sets the internal class

public void setObjectClass (Class c)

Sets a default class for objects in this collection; null resets the class to nothing.

Parameters
c the class
Throws
IllegalArgumentException if c is not a DBObject

public void setOptions (int options)

sets the default query options

public void setReadPreference (ReadPreference preference)

Sets the read preference for this collection. Will be used as default for reads from this collection; overrides DB & Connection level settings. See the * documentation for ReadPreference for more information.

Parameters
preference Read Preference to use

public void setWriteConcern (WriteConcern concern)

Set the write concern for this collection. Will be used for writes to this collection. Overrides any setting of write concern at the DB level. See the documentation for WriteConcern for more information.

Parameters
concern write concern to use

public void slaveOk ()

This method is deprecated.
Replaced with ReadPreference.SECONDARY

makes this query ok to run on a slave node

See Also
  • com.mongodb.ReadPreference.SECONDARY

public String toString ()

public abstract WriteResult update (DBObject q, DBObject o, boolean upsert, boolean multi, WriteConcern concern, DBEncoder encoder)

Performs an update operation.@return

Parameters
q search query for old object to update
o object with which to update q
upsert if the database should create the element if it does not exist
multi if the update should be applied to all objects matching (db version 1.1.3 and above). An object will not be inserted if it does not exist in the collection and upsert=true and multi=true. See http://www.mongodb.org/display/DOCS/Atomic+Operations
concern the write concern
encoder the DBEncoder to use
Throws
MongoException
MongoException

public WriteResult update (DBObject q, DBObject o, boolean upsert, boolean multi, WriteConcern concern)

Performs an update operation.@return

Parameters
q search query for old object to update
o object with which to update q
upsert if the database should create the element if it does not exist
multi if the update should be applied to all objects matching (db version 1.1.3 and above). An object will not be inserted if it does not exist in the collection and upsert=true and multi=true. See http://www.mongodb.org/display/DOCS/Atomic+Operations
concern the write concern
Throws
MongoException
MongoException

public WriteResult update (DBObject q, DBObject o)

calls update(com.mongodb.DBObject, com.mongodb.DBObject, boolean, boolean) with upsert=false and multi=false@return

Parameters
q search query for old object to update
o object with which to update q
Throws
MongoException
MongoException

public WriteResult update (DBObject q, DBObject o, boolean upsert, boolean multi)

Parameters
q search query for old object to update
o object with which to update q
upsert if the database should create the element if it does not exist
multi if the update should be applied to all objects matching (db version 1.1.3 and above) See http://www.mongodb.org/display/DOCS/Atomic+Operations
Throws
MongoException
MongoException

public WriteResult updateMulti (DBObject q, DBObject o)

calls update(com.mongodb.DBObject, com.mongodb.DBObject, boolean, boolean) with upsert=false and multi=true@return

Parameters
q search query for old object to update
o object with which to update q
Throws
MongoException
MongoException

Protected Methods

protected DBObject _checkObject (DBObject o, boolean canBeNull, boolean query)

protected boolean checkReadOnly (boolean strict)

Returns if this collection's database is read-only

Parameters
strict if an exception should be thrown if the database is read-only
Returns
  • if this collection's database is read-only
Throws
RuntimeException if the database is read-only and strict is set

protected abstract void doapply (DBObject o)

Adds any necessary fields to a given object before saving it to the collection.

Parameters
o object to which to add the fields

protected Class getInternalClass (String path)

gets the internal class