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

CAST supports Amazon DocumentDB via its com.castsoftware.nosqljava extension. As Amazon DocumentDB is MongoDB compatible, supported operations, objects and links are identical to those listed in MongoDB.

Supported Amazon DocumentDB versions

LibraryVersionSupported
Amazon Document DbUp to: 4.0(tick)

Amazon DocumentDB Identification

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

Object

Type of Property Value

Possible Value(s)

Meaning

Java MongoDB collectionInteger

1



The collection object is of type Amazon DocumentDB

Java MongoDB collectionInteger0The collection object is of type MongoDB
Java unknown MongoDB collectionInteger

1



The collection object is of type Amazon DocumentDB

Java unknown MongoDB collectionInteger0The collection object is of type MongoDB

What results can you expect?

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();
        }

    }
}
                    

For detailed information on results related to objects and links see MongoDB.

Known Limitations

  • Setting of properties related to Amazon DocumentDB identification depends on proper resolution of connection string.