public class MongoDBConnector extends java.lang.Object implements Connector
Modifier and Type | Field and Description |
---|---|
static int |
ACTION_COUNT |
static int |
ACTION_FIND |
static int |
ACTION_FINDANDMODIFY |
static int |
ACTION_FINDANDREMOVE |
static int |
ACTION_FINDONE |
static int |
ACTION_GROUP |
static int |
ACTION_INSERT |
static int |
ACTION_LIST |
static int |
ACTION_MAPREDUCE |
static int |
ACTION_REMOVE |
static int |
ACTION_UPDATE |
static int |
ACTION_UPDATEMULTI |
protected java.lang.String |
dbName |
protected java.lang.String |
hostname |
protected boolean |
isConnected |
protected boolean |
isSlaveOK |
protected java.lang.String |
password |
protected int |
port |
protected int |
timeout |
protected java.lang.String |
uri |
protected java.lang.String |
username |
Constructor and Description |
---|
MongoDBConnector(java.util.Map props)
Creates new MongoDBConnector
|
Modifier and Type | Method and Description |
---|---|
void |
close()
closes the MongoDB connections
|
long |
count(java.lang.String collName,
java.lang.String query)
returns the count of the query for the collection or -1 on failure
|
com.mongodb.DBCursor |
find(java.lang.String collName,
java.lang.String query)
returns DBCursor for all the found docs or null on failure
|
com.mongodb.DBCursor |
find(java.lang.String collName,
java.lang.String query,
java.lang.String projection)
It returns DBCursor for all the found docs with the query and the
projection or null on failure.
|
com.mongodb.DBObject |
findOne(java.lang.String collName,
java.lang.String query)
returns DBObject for the found docs with the query or null on failure
|
com.mongodb.DBObject |
findOne(java.lang.String collName,
java.lang.String query,
java.lang.String projection)
It returns DBObject for the found doc with the query and the projection
or null on failure.
|
com.mongodb.DBCollection |
getCollection(java.lang.String collName)
returns the collection or null if name is not well defined
|
static int |
getCommandID(java.lang.String cmd)
returns the id for the command or -1 if the cmd is not supported
|
java.lang.String |
getURI() |
java.lang.String |
insert(java.lang.String collName,
java.lang.String data)
returns id of the inserted doc or null on failure
|
boolean |
isConnected() |
java.lang.String[] |
list()
returns an array of collection names for the DB
|
static void |
main(java.lang.String[] args)
tests MongoDB basic operations
|
static com.mongodb.DBObject |
parse(java.lang.String jsonText)
parses a JSON text into a DBObject
|
java.lang.String |
reconnect()
It reconnects and returns null or error message upon failure
|
int |
remove(java.lang.String collName,
java.lang.String query)
returns number of removed docs for the query or -1 on failure
|
int |
update(java.lang.String collName,
java.lang.String query,
java.lang.String data)
returns number of the updated doc for the query or -1 on failure
|
int |
updateMulti(java.lang.String collName,
java.lang.String query,
java.lang.String data)
returns number of updated docs for the query or -1 on failure
|
protected java.lang.String hostname
protected java.lang.String username
protected java.lang.String password
protected java.lang.String dbName
protected java.lang.String uri
protected int port
protected int timeout
protected boolean isConnected
protected boolean isSlaveOK
public static final int ACTION_LIST
public static final int ACTION_COUNT
public static final int ACTION_FIND
public static final int ACTION_FINDONE
public static final int ACTION_FINDANDMODIFY
public static final int ACTION_FINDANDREMOVE
public static final int ACTION_INSERT
public static final int ACTION_REMOVE
public static final int ACTION_UPDATE
public static final int ACTION_UPDATEMULTI
public static final int ACTION_GROUP
public static final int ACTION_MAPREDUCE
public MongoDBConnector(java.util.Map props)
public boolean isConnected()
isConnected
in interface Connector
public java.lang.String reconnect()
public static com.mongodb.DBObject parse(java.lang.String jsonText)
public com.mongodb.DBCollection getCollection(java.lang.String collName)
public com.mongodb.DBCursor find(java.lang.String collName, java.lang.String query, java.lang.String projection) throws com.mongodb.MongoException
com.mongodb.MongoException
public com.mongodb.DBCursor find(java.lang.String collName, java.lang.String query) throws com.mongodb.MongoException
com.mongodb.MongoException
public com.mongodb.DBObject findOne(java.lang.String collName, java.lang.String query, java.lang.String projection) throws com.mongodb.MongoException
com.mongodb.MongoException
public com.mongodb.DBObject findOne(java.lang.String collName, java.lang.String query) throws com.mongodb.MongoException
com.mongodb.MongoException
public java.lang.String insert(java.lang.String collName, java.lang.String data) throws com.mongodb.MongoException
com.mongodb.MongoException
public int update(java.lang.String collName, java.lang.String query, java.lang.String data) throws com.mongodb.MongoException
com.mongodb.MongoException
public int updateMulti(java.lang.String collName, java.lang.String query, java.lang.String data) throws com.mongodb.MongoException
com.mongodb.MongoException
public int remove(java.lang.String collName, java.lang.String query) throws com.mongodb.MongoException
com.mongodb.MongoException
public long count(java.lang.String collName, java.lang.String query) throws com.mongodb.MongoException
com.mongodb.MongoException
public java.lang.String[] list() throws com.mongodb.MongoException
com.mongodb.MongoException
public static final int getCommandID(java.lang.String cmd)
public static void main(java.lang.String[] args)