|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.vz.mongodb.jackson.JacksonDBCollection<T,K>
public class JacksonDBCollection<T,K>
A DBCollection that marshals/demarshals objects to/from Jackson annotated classes. It provides a very thin wrapper over an existing DBCollection.
Nested Class Summary | |
---|---|
static class |
JacksonDBCollection.Feature
|
Constructor Summary | |
---|---|
protected |
JacksonDBCollection(com.mongodb.DBCollection dbCollection,
org.codehaus.jackson.type.JavaType type,
org.codehaus.jackson.type.JavaType keyType,
org.codehaus.jackson.map.ObjectMapper objectMapper,
Map<JacksonDBCollection.Feature,Boolean> features)
|
Method Summary | ||
---|---|---|
void |
addOption(int option)
adds a default query option |
|
K |
convertFromDbId(Object object)
|
|
long |
count()
returns the number of documents in this collection. |
|
long |
count(com.mongodb.DBObject query)
returns the number of documents that match a query. |
|
void |
createIndex(com.mongodb.DBObject keys)
calls DBCollection.createIndex(com.mongodb.DBObject, com.mongodb.DBObject) with default index options |
|
void |
createIndex(com.mongodb.DBObject keys,
com.mongodb.DBObject options)
Forces creation of an index on a set of fields, if one does not already exist. |
|
JacksonDBCollection<T,K> |
disable(JacksonDBCollection.Feature feature)
Disable the given feature |
|
List |
distinct(String key)
find distinct values for a key |
|
List |
distinct(String key,
com.mongodb.DBObject query)
find distinct values for a key |
|
void |
drop()
Drops (deletes) this collection. |
|
void |
dropIndex(com.mongodb.DBObject keys)
Drops an index from this collection |
|
void |
dropIndex(String name)
Drops an index from this collection |
|
void |
dropIndexes()
Drops all indices from this collection |
|
void |
dropIndexes(String name)
Drops an index from this collection |
|
JacksonDBCollection<T,K> |
enable(JacksonDBCollection.Feature feature)
Enable the given feature |
|
void |
ensureIndex(com.mongodb.DBObject keys)
calls DBCollection.ensureIndex(com.mongodb.DBObject, com.mongodb.DBObject) with default options |
|
void |
ensureIndex(com.mongodb.DBObject keys,
com.mongodb.DBObject optionsIN)
Creates an index on a set of fields, if one does not already exist. |
|
void |
ensureIndex(com.mongodb.DBObject keys,
String name)
calls DBCollection.ensureIndex(com.mongodb.DBObject, java.lang.String, boolean) with unique=false |
|
void |
ensureIndex(com.mongodb.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(String name)
Creates an ascending index on a field with default options, if one does not already exist. |
|
boolean |
equals(Object o)
|
|
|
fetch(Collection<DBRef<R,RK>> collection)
Fetch a collection of dbrefs. |
|
|
fetch(Collection<DBRef<R,RK>> collection,
com.mongodb.DBObject fields)
Fetch a collection of dbrefs. |
|
DBCursor<T> |
find()
Queries for all objects in this collection. |
|
DBCursor<T> |
find(com.mongodb.DBObject query)
Queries for an object in this collection. |
|
DBCursor<T> |
find(com.mongodb.DBObject query,
com.mongodb.DBObject keys)
Queries for an object in this collection. |
|
DBCursor<T> |
find(T query)
Queries for an object in this collection. |
|
DBCursor<T> |
find(T query,
T keys)
Queries for an object in this collection. |
|
T |
findAndModify(com.mongodb.DBObject query,
com.mongodb.DBObject update)
calls DBCollection.findAndModify(com.mongodb.DBObject, com.mongodb.DBObject, com.mongodb.DBObject, boolean, com.mongodb.DBObject, boolean, boolean)
with fields=null, sort=null, remove=false, returnNew=false, upsert=false |
|
T |
findAndModify(com.mongodb.DBObject query,
com.mongodb.DBObject sort,
com.mongodb.DBObject update)
calls DBCollection.findAndModify(com.mongodb.DBObject, com.mongodb.DBObject, com.mongodb.DBObject, boolean, com.mongodb.DBObject, boolean, boolean)
with fields=null, remove=false, returnNew=false, upsert=false |
|
T |
findAndModify(com.mongodb.DBObject query,
com.mongodb.DBObject fields,
com.mongodb.DBObject sort,
boolean remove,
com.mongodb.DBObject update,
boolean returnNew,
boolean upsert)
Finds the first document in the query and updates it. |
|
T |
findAndRemove(com.mongodb.DBObject query)
calls DBCollection.findAndModify(com.mongodb.DBObject, com.mongodb.DBObject, com.mongodb.DBObject, boolean, com.mongodb.DBObject, boolean, boolean)
with fields=null, sort=null, remove=true, returnNew=false, upsert=false |
|
T |
findOne()
Returns a single object from this collection. |
|
T |
findOne(com.mongodb.DBObject query)
Returns a single object from this collection matching the query. |
|
T |
findOne(com.mongodb.DBObject query,
com.mongodb.DBObject fields)
Returns a single object from this collection matching the query. |
|
T |
findOne(com.mongodb.DBObject query,
com.mongodb.DBObject fields,
com.mongodb.ReadPreference readPref)
Returns a single object from this collection matching the query. |
|
T |
findOne(T query)
Returns a single object from this collection matching the query. |
|
T |
findOne(T query,
T fields)
Returns a single object from this collection matching the query. |
|
T |
findOne(T query,
T fields,
com.mongodb.ReadPreference readPref)
Returns a single object from this collection matching the query. |
|
T |
findOneById(K id)
Find an object by the given id |
|
T |
findOneById(K id,
com.mongodb.DBObject fields)
Find an object by the given id |
|
T |
findOneById(K id,
T fields)
Find an object by the given id |
|
|
getCollection(String n,
Class<S> type,
Class<L> keyType)
Finds a collection that is prefixed with this collection's name. |
|
JacksonCollectionKey |
getCollectionKey()
Get the type of this collection |
|
long |
getCount()
calls DBCollection.getCount(com.mongodb.DBObject, com.mongodb.DBObject) with an empty query and null fields. |
|
long |
getCount(com.mongodb.DBObject query)
calls DBCollection.getCount(com.mongodb.DBObject, com.mongodb.DBObject) with null fields. |
|
long |
getCount(com.mongodb.DBObject query,
com.mongodb.DBObject fields)
calls DBCollection.getCount(com.mongodb.DBObject, com.mongodb.DBObject, long, long) with limit=0 and skip=0 |
|
long |
getCount(com.mongodb.DBObject query,
com.mongodb.DBObject fields,
long limit,
long skip)
Returns the number of documents in the collection that match the specified query |
|
long |
getCount(T query)
calls DBCollection.getCount(com.mongodb.DBObject, com.mongodb.DBObject) with null fields. |
|
long |
getCount(T query,
T fields)
calls DBCollection.getCount(com.mongodb.DBObject, com.mongodb.DBObject, long, long) with limit=0 and skip=0 |
|
long |
getCount(T query,
T fields,
long limit,
long skip)
Returns the number of documents in the collection that match the specified query |
|
com.mongodb.DB |
getDB()
Returns the database this collection is a member of. |
|
com.mongodb.DBCollection |
getDbCollection()
Get the underlying db collection |
|
String |
getFullName()
Returns the full name of this collection, with the database name as a prefix. |
|
List<com.mongodb.DBObject> |
getIndexInfo()
Return a list of the indexes for this collection. |
|
String |
getName()
Returns the name of this collection. |
|
int |
getOptions()
gets the default query options |
|
com.mongodb.ReadPreference |
getReadPreference()
Gets the read preference |
|
|
getReferenceCollection(JacksonCollectionKey collectionKey)
Get a collection for loading a reference of the given type |
|
|
getReferenceCollection(String collectionName,
org.codehaus.jackson.type.JavaType type,
org.codehaus.jackson.type.JavaType keyType)
Get a collection for loading a reference of the given type |
|
com.mongodb.CommandResult |
getStats()
gets the collections statistics ("collstats" command) |
|
com.mongodb.WriteConcern |
getWriteConcern()
Get the write concern for this collection. |
|
com.mongodb.DBObject |
group(com.mongodb.DBObject key,
com.mongodb.DBObject cond,
com.mongodb.DBObject initial,
String reduce)
calls DBCollection.group(com.mongodb.DBObject, com.mongodb.DBObject, com.mongodb.DBObject, java.lang.String, java.lang.String) with finalize=null |
|
com.mongodb.DBObject |
group(com.mongodb.DBObject key,
com.mongodb.DBObject cond,
com.mongodb.DBObject initial,
String reduce,
String finalize)
Applies a group operation |
|
com.mongodb.DBObject |
group(com.mongodb.GroupCommand cmd)
Applies a group operation |
|
int |
hashCode()
|
|
WriteResult<T,K> |
insert(List<T> list)
Inserts objects into the database. |
|
WriteResult<T,K> |
insert(List<T> list,
com.mongodb.WriteConcern concern)
Inserts objects into the database. |
|
WriteResult<T,K> |
insert(T... objects)
Inserts objects into the database. |
|
WriteResult<T,K> |
insert(T object)
Inserts an object into the database. |
|
WriteResult<T,K> |
insert(T object,
com.mongodb.WriteConcern concern)
Inserts an object into the database. |
|
WriteResult<T,K> |
insert(com.mongodb.WriteConcern concern,
T... objects)
Inserts objects into the database. |
|
boolean |
isCapped()
returns whether or not this is a capped collection |
|
boolean |
isEnabled(JacksonDBCollection.Feature feature)
Whether the given feature is enabled |
|
com.mongodb.MapReduceOutput |
mapReduce(com.mongodb.DBObject command)
Deprecated. |
|
|
mapReduce(MapReduce.MapReduceCommand<S,L> command)
Performs a map reduce operation |
|
com.mongodb.MapReduceOutput |
mapReduce(com.mongodb.MapReduceCommand command)
Deprecated. |
|
com.mongodb.MapReduceOutput |
mapReduce(String map,
String reduce,
String outputTarget,
com.mongodb.DBObject query)
Deprecated. |
|
com.mongodb.MapReduceOutput |
mapReduce(String map,
String reduce,
String outputTarget,
com.mongodb.MapReduceCommand.OutputType outputType,
com.mongodb.DBObject query)
Deprecated. |
|
WriteResult<T,K> |
remove(com.mongodb.DBObject query)
calls DBCollection.remove(com.mongodb.DBObject, com.mongodb.WriteConcern) with the default WriteConcern |
|
WriteResult<T,K> |
remove(com.mongodb.DBObject query,
com.mongodb.WriteConcern concern)
Removes objects from the database collection. |
|
WriteResult<T,K> |
remove(T object)
calls DBCollection.remove(com.mongodb.DBObject, com.mongodb.WriteConcern) with the default WriteConcern |
|
WriteResult<T,K> |
remove(T object,
com.mongodb.WriteConcern concern)
Removes objects from the database collection. |
|
WriteResult<T,K> |
removeById(K id)
calls DBCollection.remove(com.mongodb.DBObject, com.mongodb.WriteConcern) with the default WriteConcern |
|
JacksonDBCollection<T,K> |
rename(String newName)
Calls DBCollection.rename(java.lang.String, boolean) with dropTarget=false |
|
JacksonDBCollection<T,K> |
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<T,K> |
save(T object)
calls DBCollection.save(com.mongodb.DBObject, com.mongodb.WriteConcern) with default WriteConcern |
|
WriteResult<T,K> |
save(T object,
com.mongodb.WriteConcern concern)
Saves an object to this collection (does insert or update based on the object _id). |
|
void |
setHintFields(List<com.mongodb.DBObject> lst)
Set hint fields for this collection (to optimize queries). |
|
void |
setOptions(int options)
sets the default query options |
|
void |
setReadPreference(com.mongodb.ReadPreference preference)
Sets the read preference for this collection. |
|
void |
setWriteConcern(com.mongodb.WriteConcern concern)
Set the write concern for this collection. |
|
String |
toString()
|
|
WriteResult<T,K> |
update(com.mongodb.DBObject query,
com.mongodb.DBObject object)
calls DBCollection.update(com.mongodb.DBObject, com.mongodb.DBObject, boolean, boolean) with upsert=false and multi=false |
|
WriteResult<T,K> |
update(com.mongodb.DBObject query,
com.mongodb.DBObject object,
boolean upsert,
boolean multi)
calls DBCollection.update(com.mongodb.DBObject, com.mongodb.DBObject, boolean, boolean, com.mongodb.WriteConcern) with default WriteConcern. |
|
WriteResult<T,K> |
update(com.mongodb.DBObject query,
com.mongodb.DBObject object,
boolean upsert,
boolean multi,
com.mongodb.WriteConcern concern)
Performs an update operation. |
|
WriteResult<T,K> |
update(com.mongodb.DBObject query,
DBUpdate.Builder update)
Performs an update operation. |
|
WriteResult<T,K> |
update(com.mongodb.DBObject query,
DBUpdate.Builder update,
boolean upsert,
boolean multi)
Performs an update operation. |
|
WriteResult<T,K> |
update(com.mongodb.DBObject query,
DBUpdate.Builder update,
boolean upsert,
boolean multi,
com.mongodb.WriteConcern concern)
Performs an update operation. |
|
WriteResult<T,K> |
update(T query,
T object)
calls DBCollection.update(com.mongodb.DBObject, com.mongodb.DBObject, boolean, boolean) with upsert=false and multi=false |
|
WriteResult<T,K> |
update(T query,
T object,
boolean upsert,
boolean multi)
calls DBCollection.update(com.mongodb.DBObject, com.mongodb.DBObject, boolean, boolean, com.mongodb.WriteConcern) with default WriteConcern. |
|
WriteResult<T,K> |
update(T query,
T object,
boolean upsert,
boolean multi,
com.mongodb.WriteConcern concern)
Performs an update operation. |
|
WriteResult<T,K> |
updateById(K id,
DBUpdate.Builder update)
Performs an update operation. |
|
WriteResult<T,K> |
updateById(K id,
T object)
calls DBCollection.update(com.mongodb.DBObject, com.mongodb.DBObject, boolean, boolean) with upsert=false and multi=false |
|
WriteResult<T,K> |
updateMulti(com.mongodb.DBObject query,
com.mongodb.DBObject object)
calls DBCollection.update(com.mongodb.DBObject, com.mongodb.DBObject, boolean, boolean) with upsert=false and multi=true |
|
WriteResult<T,K> |
updateMulti(com.mongodb.DBObject query,
DBUpdate.Builder update)
calls DBCollection.update(com.mongodb.DBObject, com.mongodb.DBObject, boolean, boolean) with upsert=false and multi=true |
|
WriteResult<T,K> |
updateMulti(T query,
T object)
calls DBCollection.update(com.mongodb.DBObject, com.mongodb.DBObject, boolean, boolean) with upsert=false and multi=true |
|
static
|
wrap(com.mongodb.DBCollection dbCollection,
Class<T> type)
Wraps a DB collection in a JacksonDBCollection |
|
static
|
wrap(com.mongodb.DBCollection dbCollection,
Class<T> type,
Class<K> keyType)
Wraps a DB collection in a JacksonDBCollection |
|
static
|
wrap(com.mongodb.DBCollection dbCollection,
Class<T> type,
Class<K> keyType,
Class<?> view)
Wraps a DB collection in a JacksonDBCollection |
|
static
|
wrap(com.mongodb.DBCollection dbCollection,
Class<T> type,
Class<K> keyType,
org.codehaus.jackson.map.ObjectMapper objectMapper)
Wraps a DB collection in a JacksonDBCollection, using the given object mapper. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
protected JacksonDBCollection(com.mongodb.DBCollection dbCollection, org.codehaus.jackson.type.JavaType type, org.codehaus.jackson.type.JavaType keyType, org.codehaus.jackson.map.ObjectMapper objectMapper, Map<JacksonDBCollection.Feature,Boolean> features)
Method Detail |
---|
public static <T> JacksonDBCollection<T,Object> wrap(com.mongodb.DBCollection dbCollection, Class<T> type)
dbCollection
- The DB collection to wraptype
- The type of objects to deserialise to
public static <T,K> JacksonDBCollection<T,K> wrap(com.mongodb.DBCollection dbCollection, Class<T> type, Class<K> keyType)
dbCollection
- The DB collection to wraptype
- The type of objects to deserialise tokeyType
- The type of the objects key
public static <T,K> JacksonDBCollection<T,K> wrap(com.mongodb.DBCollection dbCollection, Class<T> type, Class<K> keyType, Class<?> view)
dbCollection
- The DB collection to wraptype
- The type of objects to deserialise tokeyType
- The type of the objects keyview
- The JSON view to use for serialisation
public static <T,K> JacksonDBCollection<T,K> wrap(com.mongodb.DBCollection dbCollection, Class<T> type, Class<K> keyType, org.codehaus.jackson.map.ObjectMapper objectMapper)
MongoJacksonMapperModule.configure(org.codehaus.jackson.map.ObjectMapper)
.
dbCollection
- The DB collection to wraptype
- The type of objects to deserialise toobjectMapper
- The ObjectMapper to configure.
public JacksonDBCollection<T,K> enable(JacksonDBCollection.Feature feature)
feature
- The feature to enable
public JacksonDBCollection<T,K> disable(JacksonDBCollection.Feature feature)
feature
- The feature to disable
public boolean isEnabled(JacksonDBCollection.Feature feature)
feature
- The feature to check
public com.mongodb.DBCollection getDbCollection()
public WriteResult<T,K> insert(T object) throws com.mongodb.MongoException
object
- The object to insert
com.mongodb.MongoException
- If an error occurredpublic WriteResult<T,K> insert(T object, com.mongodb.WriteConcern concern) throws com.mongodb.MongoException
object
- The object to insertconcern
- the write concern
com.mongodb.MongoException
- If an error occurredpublic WriteResult<T,K> insert(T... objects) throws com.mongodb.MongoException
objects
- The objects to insert
com.mongodb.MongoException
- If an error occurredpublic WriteResult<T,K> insert(com.mongodb.WriteConcern concern, T... objects) throws com.mongodb.MongoException
objects
- The objects to insertconcern
- the write concern
com.mongodb.MongoException
- If an error occurredpublic WriteResult<T,K> insert(List<T> list) throws com.mongodb.MongoException
list
- The objects to insert
com.mongodb.MongoException
- If an error occurredpublic WriteResult<T,K> insert(List<T> list, com.mongodb.WriteConcern concern) throws com.mongodb.MongoException
list
- The objects to insertconcern
- the write concern
com.mongodb.MongoException
- If an error occurredpublic WriteResult<T,K> update(com.mongodb.DBObject query, com.mongodb.DBObject object, boolean upsert, boolean multi, com.mongodb.WriteConcern concern) throws com.mongodb.MongoException
query
- search query for old object to updateobject
- object with which to update queryupsert
- if the database should create the element if it does not existmulti
- 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+Operationsconcern
- the write concern
com.mongodb.MongoException
- If an error occurredpublic WriteResult<T,K> update(com.mongodb.DBObject query, DBUpdate.Builder update, boolean upsert, boolean multi, com.mongodb.WriteConcern concern) throws com.mongodb.MongoException
query
- search query for old object to updateupdate
- update with which to update queryupsert
- if the database should create the element if it does not existmulti
- 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+Operationsconcern
- the write concern
com.mongodb.MongoException
- If an error occurredpublic WriteResult<T,K> update(T query, T object, boolean upsert, boolean multi, com.mongodb.WriteConcern concern) throws com.mongodb.MongoException
query
- search query for old object to updateobject
- object with which to update queryupsert
- if the database should create the element if it does not existmulti
- 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+Operationsconcern
- the write concern
com.mongodb.MongoException
- If an error occurredpublic WriteResult<T,K> update(com.mongodb.DBObject query, com.mongodb.DBObject object, boolean upsert, boolean multi) throws com.mongodb.MongoException
DBCollection.update(com.mongodb.DBObject, com.mongodb.DBObject, boolean, boolean, com.mongodb.WriteConcern)
with default WriteConcern.
query
- search query for old object to updateobject
- object with which to update qupsert
- if the database should create the element if it does not existmulti
- 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
com.mongodb.MongoException
- If an error occurredpublic WriteResult<T,K> update(com.mongodb.DBObject query, DBUpdate.Builder update, boolean upsert, boolean multi) throws com.mongodb.MongoException
query
- search query for old object to updateupdate
- update with which to update queryupsert
- if the database should create the element if it does not existmulti
- 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
com.mongodb.MongoException
- If an error occurredpublic WriteResult<T,K> update(T query, T object, boolean upsert, boolean multi) throws com.mongodb.MongoException
DBCollection.update(com.mongodb.DBObject, com.mongodb.DBObject, boolean, boolean, com.mongodb.WriteConcern)
with default WriteConcern.
query
- search query for old object to updateobject
- object with which to update qupsert
- if the database should create the element if it does not existmulti
- 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
com.mongodb.MongoException
- If an error occurredpublic WriteResult<T,K> update(com.mongodb.DBObject query, com.mongodb.DBObject object) throws com.mongodb.MongoException
DBCollection.update(com.mongodb.DBObject, com.mongodb.DBObject, boolean, boolean)
with upsert=false and multi=false
query
- search query for old object to updateobject
- object with which to update query
com.mongodb.MongoException
- If an error occurredpublic WriteResult<T,K> update(com.mongodb.DBObject query, DBUpdate.Builder update) throws com.mongodb.MongoException
query
- search query for old object to updateupdate
- update with which to update query
com.mongodb.MongoException
- If an error occurredpublic WriteResult<T,K> update(T query, T object) throws com.mongodb.MongoException
DBCollection.update(com.mongodb.DBObject, com.mongodb.DBObject, boolean, boolean)
with upsert=false and multi=false
query
- search query for old object to updateobject
- object with which to update query
com.mongodb.MongoException
- If an error occurredpublic WriteResult<T,K> updateById(K id, T object) throws com.mongodb.MongoException
DBCollection.update(com.mongodb.DBObject, com.mongodb.DBObject, boolean, boolean)
with upsert=false and multi=false
id
- the id of the object to updateobject
- object with which to update query
com.mongodb.MongoException
- If an error occurredpublic WriteResult<T,K> updateById(K id, DBUpdate.Builder update) throws com.mongodb.MongoException
id
- The id of the document to updateupdate
- update with which to update query
com.mongodb.MongoException
- If an error occurredpublic WriteResult<T,K> updateMulti(com.mongodb.DBObject query, com.mongodb.DBObject object) throws com.mongodb.MongoException
DBCollection.update(com.mongodb.DBObject, com.mongodb.DBObject, boolean, boolean)
with upsert=false and multi=true
query
- search query for old object to updateobject
- object with which to update query
com.mongodb.MongoException
- If an error occurredpublic WriteResult<T,K> updateMulti(com.mongodb.DBObject query, DBUpdate.Builder update) throws com.mongodb.MongoException
DBCollection.update(com.mongodb.DBObject, com.mongodb.DBObject, boolean, boolean)
with upsert=false and multi=true
query
- search query for old object to updateupdate
- update with which to update query
com.mongodb.MongoException
- If an error occurredpublic WriteResult<T,K> updateMulti(T query, T object) throws com.mongodb.MongoException
DBCollection.update(com.mongodb.DBObject, com.mongodb.DBObject, boolean, boolean)
with upsert=false and multi=true
query
- search query for old object to updateobject
- object with which to update query
com.mongodb.MongoException
- If an error occurredpublic WriteResult<T,K> remove(com.mongodb.DBObject query, com.mongodb.WriteConcern concern) throws com.mongodb.MongoException
query
- the object that documents to be removed must matchconcern
- WriteConcern for this operation
com.mongodb.MongoException
- If an error occurredpublic WriteResult<T,K> remove(T object, com.mongodb.WriteConcern concern) throws com.mongodb.MongoException
object
- the object that documents to be removed must matchconcern
- WriteConcern for this operation
com.mongodb.MongoException
- If an error occurredpublic WriteResult<T,K> remove(com.mongodb.DBObject query) throws com.mongodb.MongoException
DBCollection.remove(com.mongodb.DBObject, com.mongodb.WriteConcern)
with the default WriteConcern
query
- the query that documents to be removed must match
com.mongodb.MongoException
- If an error occurredpublic WriteResult<T,K> remove(T object) throws com.mongodb.MongoException
DBCollection.remove(com.mongodb.DBObject, com.mongodb.WriteConcern)
with the default WriteConcern
object
- the object that documents to be removed must match
com.mongodb.MongoException
- If an error occurredpublic WriteResult<T,K> removeById(K id) throws com.mongodb.MongoException
DBCollection.remove(com.mongodb.DBObject, com.mongodb.WriteConcern)
with the default WriteConcern
id
- the id of the document to remove
com.mongodb.MongoException
- If an error occurredpublic T findAndModify(com.mongodb.DBObject query, com.mongodb.DBObject fields, com.mongodb.DBObject sort, boolean remove, com.mongodb.DBObject update, boolean returnNew, boolean upsert)
query
- query to matchfields
- fields to be returnedsort
- sort to apply before picking first documentremove
- if true, document found will be removedupdate
- update to applyreturnNew
- 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)
public T findAndModify(com.mongodb.DBObject query, com.mongodb.DBObject sort, com.mongodb.DBObject update)
DBCollection.findAndModify(com.mongodb.DBObject, com.mongodb.DBObject, com.mongodb.DBObject, boolean, com.mongodb.DBObject, boolean, boolean)
with fields=null, remove=false, returnNew=false, upsert=false
query
- The querysort
- The sortupdate
- The update to apply
public T findAndModify(com.mongodb.DBObject query, com.mongodb.DBObject update)
DBCollection.findAndModify(com.mongodb.DBObject, com.mongodb.DBObject, com.mongodb.DBObject, boolean, com.mongodb.DBObject, boolean, boolean)
with fields=null, sort=null, remove=false, returnNew=false, upsert=false
query
- The queryupdate
- The update to apply
public T findAndRemove(com.mongodb.DBObject query)
DBCollection.findAndModify(com.mongodb.DBObject, com.mongodb.DBObject, com.mongodb.DBObject, boolean, com.mongodb.DBObject, boolean, boolean)
with fields=null, sort=null, remove=true, returnNew=false, upsert=false
query
- The query
public final void createIndex(com.mongodb.DBObject keys) throws com.mongodb.MongoException
DBCollection.createIndex(com.mongodb.DBObject, com.mongodb.DBObject)
with default index options
keys
- an object with a key set of the fields desired for the index
com.mongodb.MongoException
- If an error occurredpublic void createIndex(com.mongodb.DBObject keys, com.mongodb.DBObject options) throws com.mongodb.MongoException
keys
- The keys to indexoptions
- The options
com.mongodb.MongoException
- If an error occurredpublic final void ensureIndex(String name)
name
- name of field to index onpublic final void ensureIndex(com.mongodb.DBObject keys) throws com.mongodb.MongoException
DBCollection.ensureIndex(com.mongodb.DBObject, com.mongodb.DBObject)
with default options
keys
- an object with a key set of the fields desired for the index
com.mongodb.MongoException
- If an error occurredpublic void ensureIndex(com.mongodb.DBObject keys, String name) throws com.mongodb.MongoException
DBCollection.ensureIndex(com.mongodb.DBObject, java.lang.String, boolean)
with unique=false
keys
- fields to use for indexname
- an identifier for the index
com.mongodb.MongoException
- If an error occurredpublic void ensureIndex(com.mongodb.DBObject keys, String name, boolean unique) throws com.mongodb.MongoException
keys
- fields to use for indexname
- an identifier for the index. If null or empty, the default name will be used.unique
- if the index should be unique
com.mongodb.MongoException
- If an error occurredpublic void ensureIndex(com.mongodb.DBObject keys, com.mongodb.DBObject optionsIN) throws com.mongodb.MongoException
keys
- an object with a key set of the fields desired for the indexoptionsIN
- options for the index (name, unique, etc)
com.mongodb.MongoException
- If an error occurredpublic void resetIndexCache()
public void setHintFields(List<com.mongodb.DBObject> lst)
lst
- a list of DBObject
s to be used as hintspublic DBCursor<T> find(com.mongodb.DBObject query) throws com.mongodb.MongoException
query
- object for which to search
com.mongodb.MongoException
- If an error occurredpublic DBCursor<T> find(T query) throws com.mongodb.MongoException
query
- object for which to search
com.mongodb.MongoException
- If an error occurredpublic final DBCursor<T> find(com.mongodb.DBObject query, com.mongodb.DBObject keys)
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);
query
- object for which to searchkeys
- fields to return
public final DBCursor<T> find(T query, T keys)
An empty DBObject will match every document in the collection. Regardless of fields specified, the _id fields are always returned.
To keys object should have non null values for every key that you want to return
query
- object for which to searchkeys
- fields to return
public final DBCursor<T> find() throws com.mongodb.MongoException
com.mongodb.MongoException
- If an error occurredpublic T findOne() throws com.mongodb.MongoException
null
if the collection is empty
com.mongodb.MongoException
- If an error occurredpublic T findOneById(K id) throws com.mongodb.MongoException
id
- The id
com.mongodb.MongoException
- If an error occurredpublic T findOneById(K id, com.mongodb.DBObject fields) throws com.mongodb.MongoException
id
- The id
com.mongodb.MongoException
- If an error occurredpublic T findOneById(K id, T fields) throws com.mongodb.MongoException
id
- The id
com.mongodb.MongoException
- If an error occurredpublic T findOne(com.mongodb.DBObject query) throws com.mongodb.MongoException
query
- the query object
null
if no such object exists
com.mongodb.MongoException
- If an error occurredpublic T findOne(T query) throws com.mongodb.MongoException
query
- the query object
null
if no such object exists
com.mongodb.MongoException
- If an error occurredpublic T findOne(com.mongodb.DBObject query, com.mongodb.DBObject fields)
query
- the query objectfields
- the fields to return
null
if no such object existspublic T findOne(T query, T fields)
query
- the query objectfields
- an object for which every non null field will be returned
null
if no such object existspublic T findOne(com.mongodb.DBObject query, com.mongodb.DBObject fields, com.mongodb.ReadPreference readPref)
query
- the query objectfields
- fields to returnreadPref
- The read preference
null
if no such object existspublic T findOne(T query, T fields, com.mongodb.ReadPreference readPref)
query
- the query objectfields
- an object for which every non null field will be returnedreadPref
- The read preferences
null
if no such object existspublic <R,RK> List<R> fetch(Collection<DBRef<R,RK>> collection)
R
- The type of the referencecollection
- the collection to fetch
public <R,RK> List<R> fetch(Collection<DBRef<R,RK>> collection, com.mongodb.DBObject fields)
collection
- the collection to fetchfields
- The fields to retrieve for each of the documents
public final WriteResult<T,K> save(T object)
DBCollection.save(com.mongodb.DBObject, com.mongodb.WriteConcern)
with default WriteConcern
object
- the object to save
will add _id
field to jo if needed
public WriteResult<T,K> save(T object, com.mongodb.WriteConcern concern) throws com.mongodb.MongoException
object
- the DBObject
to saveconcern
- the write concern
com.mongodb.MongoException
- If an error occurredpublic void dropIndexes() throws com.mongodb.MongoException
com.mongodb.MongoException
- If an error occurredpublic void dropIndexes(String name) throws com.mongodb.MongoException
name
- the index name
com.mongodb.MongoException
- If an error occurredpublic void drop() throws com.mongodb.MongoException
com.mongodb.MongoException
- If an error occurredpublic long count() throws com.mongodb.MongoException
com.mongodb.MongoException
- If an error occurredpublic long count(com.mongodb.DBObject query) throws com.mongodb.MongoException
query
- query to match
com.mongodb.MongoException
- If an error occurredpublic long getCount() throws com.mongodb.MongoException
DBCollection.getCount(com.mongodb.DBObject, com.mongodb.DBObject)
with an empty query and null fields.
com.mongodb.MongoException
- If an error occurredpublic long getCount(com.mongodb.DBObject query) throws com.mongodb.MongoException
DBCollection.getCount(com.mongodb.DBObject, com.mongodb.DBObject)
with null fields.
query
- query to match
com.mongodb.MongoException
- If an error occurredpublic long getCount(T query) throws com.mongodb.MongoException
DBCollection.getCount(com.mongodb.DBObject, com.mongodb.DBObject)
with null fields.
query
- query to match
com.mongodb.MongoException
- If an error occurredpublic long getCount(com.mongodb.DBObject query, com.mongodb.DBObject fields) throws com.mongodb.MongoException
DBCollection.getCount(com.mongodb.DBObject, com.mongodb.DBObject, long, long)
with limit=0 and skip=0
query
- query to matchfields
- fields to return
com.mongodb.MongoException
- If an error occurredpublic long getCount(T query, T fields) throws com.mongodb.MongoException
DBCollection.getCount(com.mongodb.DBObject, com.mongodb.DBObject, long, long)
with limit=0 and skip=0
query
- query to matchfields
- fields to return
com.mongodb.MongoException
- If an error occurredpublic long getCount(com.mongodb.DBObject query, com.mongodb.DBObject fields, long limit, long skip) throws com.mongodb.MongoException
query
- query to select documents to countfields
- fields to returnlimit
- limit the count to this valueskip
- number of entries to skip
com.mongodb.MongoException
- If an error occurredpublic long getCount(T query, T fields, long limit, long skip) throws com.mongodb.MongoException
query
- query to select documents to countfields
- fields to returnlimit
- limit the count to this valueskip
- number of entries to skip
com.mongodb.MongoException
- If an error occurredpublic JacksonDBCollection<T,K> rename(String newName) throws com.mongodb.MongoException
DBCollection.rename(java.lang.String, boolean)
with dropTarget=false
newName
- new collection name (not a full namespace)
com.mongodb.MongoException
- If an error occurredpublic JacksonDBCollection<T,K> rename(String newName, boolean dropTarget) throws com.mongodb.MongoException
newName
- new collection name (not a full namespace)dropTarget
- if a collection with the new name exists, whether or not to drop it
com.mongodb.MongoException
- If an error occurredpublic com.mongodb.DBObject group(com.mongodb.DBObject key, com.mongodb.DBObject cond, com.mongodb.DBObject initial, String reduce) throws com.mongodb.MongoException
DBCollection.group(com.mongodb.DBObject, com.mongodb.DBObject, com.mongodb.DBObject, java.lang.String, java.lang.String)
with finalize=null
key
- - { a : true }cond
- - optional condition on queryreduce
- javascript reduce functioninitial
- initial value for first match on a key
com.mongodb.MongoException
- If an error occurredpublic com.mongodb.DBObject group(com.mongodb.DBObject key, com.mongodb.DBObject cond, com.mongodb.DBObject initial, String reduce, String finalize) throws com.mongodb.MongoException
key
- - { a : true }cond
- - optional condition on queryreduce
- javascript reduce functioninitial
- initial value for first match on a keyfinalize
- An optional function that can operate on the result(s) of the reduce function.
com.mongodb.MongoException
- If an error occurredpublic com.mongodb.DBObject group(com.mongodb.GroupCommand cmd)
cmd
- the group command
com.mongodb.MongoException
public List distinct(String key)
key
- The key
public List distinct(String key, com.mongodb.DBObject query)
key
- The keyquery
- query to match
@Deprecated public com.mongodb.MapReduceOutput mapReduce(String map, String reduce, String outputTarget, com.mongodb.DBObject query) throws com.mongodb.MongoException
map
- map function in javascript codeoutputTarget
- optional - leave null if want to use temp collectionreduce
- reduce function in javascript codequery
- to match
com.mongodb.MongoException
- If an error occurred@Deprecated public com.mongodb.MapReduceOutput mapReduce(String map, String reduce, String outputTarget, com.mongodb.MapReduceCommand.OutputType outputType, com.mongodb.DBObject query) throws com.mongodb.MongoException
map
- map function in javascript codeoutputTarget
- optional - leave null if want to use temp collectionoutputType
- set the type of job outputreduce
- reduce function in javascript codequery
- to match
com.mongodb.MongoException
- If an error occurred@Deprecated public com.mongodb.MapReduceOutput mapReduce(com.mongodb.MapReduceCommand command) throws com.mongodb.MongoException
command
- object representing the parameters
com.mongodb.MongoException
- If an error occurred@Deprecated public com.mongodb.MapReduceOutput mapReduce(com.mongodb.DBObject command) throws com.mongodb.MongoException
command
- object representing the parameters
com.mongodb.MongoException
- If an error occurredpublic <S,L> MapReduceOutput<S,L> mapReduce(MapReduce.MapReduceCommand<S,L> command) throws com.mongodb.MongoException
command
- The command to execute
com.mongodb.MongoException
- If an error occurredpublic List<com.mongodb.DBObject> getIndexInfo()
public void dropIndex(com.mongodb.DBObject keys) throws com.mongodb.MongoException
keys
- keys of the index
com.mongodb.MongoException
- If an error occurredpublic void dropIndex(String name) throws com.mongodb.MongoException
name
- name of index to drop
com.mongodb.MongoException
- If an error occurredpublic com.mongodb.CommandResult getStats()
public boolean isCapped()
public <S,L> JacksonDBCollection<S,L> getCollection(String n, Class<S> type, Class<L> keyType)
Which is equivalent toDBCollection users = mongo.getCollection( "wiki" ).getCollection( "users" );
DBCollection users = mongo.getCollection( "wiki.users" );
n
- the name of the collection to findtype
- The type of the collection
public String getName()
public String getFullName()
public com.mongodb.DB getDB()
public int hashCode()
hashCode
in class Object
public boolean equals(Object o)
equals
in class Object
public String toString()
toString
in class Object
public void setWriteConcern(com.mongodb.WriteConcern concern)
WriteConcern
for more information.
concern
- write concern to usepublic com.mongodb.WriteConcern getWriteConcern()
public void setReadPreference(com.mongodb.ReadPreference preference)
ReadPreference
for more information.
preference
- Read Preference to usepublic com.mongodb.ReadPreference getReadPreference()
public void addOption(int option)
option
- The option to addpublic void setOptions(int options)
options
- The optionspublic void resetOptions()
public int getOptions()
public JacksonCollectionKey getCollectionKey()
public <T,K> JacksonDBCollection<T,K> getReferenceCollection(String collectionName, org.codehaus.jackson.type.JavaType type, org.codehaus.jackson.type.JavaType keyType)
collectionName
- The name of the collectiontype
- The type of the objectkeyType
- the type of the id
public <T,K> JacksonDBCollection<T,K> getReferenceCollection(JacksonCollectionKey collectionKey)
collectionKey
- The key for the collection
public K convertFromDbId(Object object)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |