Ankit
Ankit

Reputation: 603

Is there any way to use generics In MongoDB Client?

I am using the mongoDB client in my standalone Java Application. I am wondering when I am not able to use Generics in this client program. Following sample of the code I am using

public class MongoDB_Client {
public static void main(String[] args) {
    try{

    MongoClient monog_Client=new MongoClient("localhost",27017);

    DB db=monog_Client.getDB("test");

    DBCollection getcCollection=db.getCollection("products");


    if(getcCollection.equals("products")) {

    DBCollection collection_data = db.getCollection("products1");

    System.out.println("Collection products1 getting successfully");

     DBObject myDoc = collection_data.findOne();

     DBCursor cursor = collection_data.find();
     int j =1;
     while (cursor.hasNext()) { 
     System.out.println("Inserted Document: "+j); 
     System.out.println(cursor.next()); 
       j++;
        }
       }}

Upvotes: 1

Views: 221

Answers (1)

Santosh
Santosh

Reputation: 121

When Mongo Client connects with MONGODB Database by Java code. If you are not using HASH Map then there is no possibility for using Generics. If you are using then compilation problem will come.

Upvotes: 1

Related Questions