Page tree
Skip to end of metadata
Go to start of metadata

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

Supported Libraries

Supported Operations

For Storing the data
 Insert Operation APIs
  • 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
For Fetching the data
 Select Operation APIs
  • 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
For Removing the data
 Delete Operation APIs
  • 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
For Updating the data
 Update Operation APIs
  • 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

Links

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

 Click here to expand...
  • getCollection
  • countDocuments
  • find 
  • count
  • findOneAndDelete
  • findOneandReplace
  • findOneAndUpdate
  • aggregate
  • distinct
  • findOne
  • getCount
  • getName
  • group
  • findAndModify
  • findAndRemove
useUpdateLink
 Click here to expand...
  • update
  • updateOne
  • updateMany
  • findOneAndUpdate
  • fineOneAndReplace
  • findAndModify
  • rename
  • replaceOne
useDeleteLink
 Click here to expand...
  • findOneAndDelete
  • drop
  • deleteOne
  • deleteMany
  • dropIndex
  • dropIndexes
  • remove
  • findAndRemove
useInsertLink
 Click here to expand...
  • insert
  • insertOne
  • insertMany
  • bulkWrite
  • save

*Bulkops results in the links as per the operations used

Amazon DocumentDB Identification

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

Object

Property Description

Type of Property Value

Possible Value(s)

Meaning

Java MongoDB collectionIs an Amazon DocumentDB collection?Integer

1



The collection object is of type Amazon DocumentDB

0The collection object is of type MongoDB
Java unknown MongoDB collectionIs an Amazon DocumentDB collection?Integer

1




The collection object is of type Amazon DocumentDB

0The collection object is of type MongoDB

What results can you expect?

Once the analysis/snapshot generation is complete, you can view the results in the normal manner (for example via CAST Enlighten). Some examples are shown below.

Creation of Database and Collection 

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

Insert Operation

 Click here to expand...
public void insertDocuments(DBObject[] documents) {
		userCol.insert(documents);	
	}

Select Operation

 Click here to expand...
public void getCollection() {
		DBCollection col =  db.getCollection("User");
	}

Update Operation

 Click here to expand...
public void updateDoc(DBObject query, DBObject update) {
		userCol.update(query, update);
	}

Delete Operation

 Click here to expand...


Amazon DocumentDB Identification

 Amazon DocumentDB Identification
Sample Code
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();
        }
 
    }
}

Evolution

  • There will be no connection object created.
  • Better resolution for database and collection name
  • Support for CRUD APIs com.mongodb.client.MongoCollection

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.
  • No labels