Select JSON documents from a Db2 database
You can use one of several overloaded DBCollection.find()
methods
to select documents.
The following snippet from a Java™ program
demonstrates how to select JSON documents:
DBCollection empColl = db.getCollection("employees");
//Looking for employees that are named 'Joe'
DBCursor cursor = empColl.find(new BasicDBObject("name", "Joe"));
try{
while(cursor.hasNext()){
DBObject obj = cursor.next();
doSomething(obj);
}
}finally{
//Close the cursor no matter what
cursor.close();
}
Here are some example of the overloaded
DBCollection.find()
method:DBCollection.find(com.ibm.nosql.json.api.DBObject query)
DBCollection.find(com.ibm.nosql.json.api.DBObject query, DBObject fields)
DBCollection.find(com.ibm.nosql.json.api.DBObject, com.ibm.nosql.json.api.DBObject, int, int)
DBCollection.findOne(com.ibm.nosql.json.api.DBObject)
To obtain specific the query output, consider using the following
methods:
DBCursor.sort(com.ibm.nosql.json.api.DBObject)
DBCursor.limit(int)
DBCursor.skip(int)