This documentation is not maintained. Please refer to doc.castsoftware.com/technologies to find the latest updates.

CAST supports MongoDB via its com.castsoftware.nosqljava extension. Details about how this support is provided for Java source code is discussed below.

Supported Libraries

LibraryVersionSupported
Jongo Up to: 1.4.0

Mongo Java Driver Up to: 3.12.8

Supported Operations

Operation

Methods supported

Insert

com.mongodb.DBCollection.insert

com.mongodb.client.MongoCollection.insertOne

com.mongodb.client.MongoCollection.insertMany

com.mongodb.client.MongoCollection.bulkWrite

com.mongodb.DBCollection.save

org.jongo.MongoCollection.insert

org.jongo.MongoCollection.save

Select

com.mongodb.client.MongoDatabase.getCollection

com.mongodb.client.MongoCollection.countDocuments

com.mongodb.client.MongoCollection.count

com.mongodb.client.MongoCollection.find

com.mongodb.client.MongoCollection.findOneAndDelete

com.mongodb.client.MongoCollection.findOneAndReplace

com.mongodb.client.MongoCollection.findOneAndUpdate

com.mongodb.DB.getCollection

com.mongodb.DBCollection.aggregate

com.mongodb.DBCollection.count

com.mongodb.DBCollection.distinct

com.mongodb.DBCollection.find

com.mongodb.DBCollection.findOne

com.mongodb.DBCollection.getCollection

com.mongodb.DBCollection.getCount

com.mongodb.DBCollection.getName

com.mongodb.DBCollection.group

com.mongodb.DBCollection.findAndModify

com.mongodb.DBCollection.findAndRemove

org.jongo.Jongo.getCollection

org.jongo.MongoCollection.aggregate

org.jongo.MongoCollection.count

org.jongo.MongoCollection.distinct

org.jongo.MongoCollection.find

org.jongo.MongoCollection.findAndModify

org.jongo.MongoCollection.findOne

org.jongo.MongoCollection.getDBCollection

org.jongo.MongoCollection.getName

Delete

com.mongodb.client.MongoCollection.drop

com.mongodb.client.MongoCollection.deleteOne

com.mongodb.client.MongoCollection.deleteMany

com.mongodb.client.MongoCollection.findOneAndDelete

com.mongodb.DBCollection.drop

com.mongodb.DBCollection.dropIndex

com.mongodb.DBCollection.findAndRemove

org.jongo.MongoCollection.drop

org.jongo.MongoCollection.dropIndex

org.jongo.MongoCollection.dropIndexes

org.jongo.MongoCollection.remove

Update

com.mongodb.client.MongoCollection.updateOne

com.mongodb.client.MongoCollection.updateMany

com.mongodb.client.MongoCollection.findOneAndReplace

com.mongodb.client.MongoCollection.findOneAndUpdate

org.jongo.MongoCollection.update

com.mongodb.DBCollection.update

com.mongodb.DBCollection.updateMulti

com.mongodb.DBCollection.findAndModify

com.mongodb.client.MongoCollection.replaceOne

Objects

IconDescription

Java MongoDB database

Java MongoDB collection

Java unknown MongoDB database

Java unknown MongoDB collection
Link typeSource and destination of linkMethods supported
belongsTo

From Java MongoDB collection object to Java MongoDB database object

-
useLinkBetween the caller Java Method objects (constructors also) and Java Mongo Collection Object

mapReduce

createCollection

useSelectLink

Between the caller Java Method objects (constructors also) and Java Mongo Collection Object

getCollection

countDocuments

find 

count

findOneAndDelete

findOneandReplace

findOneAndUpdate

aggregate

distinct

findOne

getCount

getName

group

findAndModify

findAndRemove

useUpdateLinkBetween the caller Java Method objects (constructors also) and Java Mongo Collection Object

update

updateOne

updateMany

findOneAndUpdate

fineOneAndReplace

findAndModify

rename

replaceOne

useDeleteLinkBetween the caller Java Method objects (constructors also) and Java Mongo Collection Object

findOneAndDelete

drop

deleteOne

deleteMany

dropIndex

dropIndexes

remove

findAndRemove

useInsertLinkBetween the caller Java Method objects (constructors also) and Java Mongo Collection Object

insert

insertOne

insertMany

bulkWrite

save

Amazon DocumentDB Identification

The below mentioned objects have properties to indicate whether the object is of type MongoDB or Amazon DocumentDB:

Java MongoDB collection object

Property Description

Type of Property Value

Value: Meaning

Is an Amazon DocumentDB collection?Integer

1: The collection object is of type Amazon DocumentDB

0: The collection object is of type MongoDB

Java unknown MongoDB collection object

Property Description

Type of Property Value

Value: Meaning

Is an Amazon DocumentDB collection?Integer

1: The collection object is of type Amazon DocumentDB

0: The collection object is of type MongoDB

What results can you expect?

Some example scenarios are shown below:

Creation of Database and Collection 

public MongoUserDAO(DB db) {
		Mongo mongo = new Mongo();
		db = mongo.getDB("TestDatabase");
		db.createCollection("User", dbo);
}

Insert Operation

public void insertDocuments(DBObject[] documents) {
		userCol.insert(documents);	
	}

Select Operation

public void getCollection() {
		DBCollection col =  db.getCollection("User");
	}

Update Operation

public void updateDoc(DBObject query, DBObject update) {
		userCol.update(query, update);
	}

Delete Operation

Amazon DocumentDB Identification

package com.sample.app;
 
import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;
import com.mongodb.ServerAddress;
import com.mongodb.MongoException;
import com.mongodb.client.MongoCursor;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.MongoCollection;
import org.bson.Document;
 
 
public final class App {
    private App() {
    }
    public static void main(String[] args) {
 
        String connectionString = "mongodb://root:rootroot@sample-cluster.cluster-cqjaxx9hbhi0.us-west-2.docdb.amazonaws.com:27017/?replicaSet=rs0&readpreference=secondaryPreferred";
 
        MongoClientURI clientURI = new MongoClientURI(connectionString);
        MongoClient mongoClient = new MongoClient(clientURI);
 
        MongoDatabase testDB = mongoClient.getDatabase("library");
        MongoCollection<Document> numbersCollection = testDB.getCollection("books");
 
        Document doc = new Document("name", "title").append("value", "Harry Potter");
        numbersCollection.insertOne(doc);
 
        MongoCursor<Document> cursor = numbersCollection.find().iterator();
        try {
            while (cursor.hasNext()) {
                System.out.println(cursor.next().toJson());
            }
        } finally {
            cursor.close();
        }
 
    }
}

Known Limitations

  • For the method 'mapReduce' the type of link produced is 'useLink' as its type is not determined
  • If collection name is not resolved in the CRUD API, then link is created with unknown collection object.
  • Setting of properties related to Amazon DocumentDB identification depends on proper resolution of connection string.