You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Sebb (Jira)" <ji...@apache.org> on 2020/03/04 12:47:00 UTC

[jira] [Resolved] (BSF-45) Error trying to access a MongoDB collection under Apache BSF script

     [ https://issues.apache.org/jira/browse/BSF-45?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sebb resolved BSF-45.
---------------------
    Resolution: Information Provided

> Error trying to access a MongoDB collection under Apache BSF script
> -------------------------------------------------------------------
>
>                 Key: BSF-45
>                 URL: https://issues.apache.org/jira/browse/BSF-45
>             Project: Commons BSF
>          Issue Type: Bug
>          Components: BSF-2.x
>    Affects Versions: BSF-2.4
>         Environment: Java 8
> BSF 2.4.0
>            Reporter: Kleyson Rios
>            Priority: Major
>         Attachments: exception.txt
>
>
> I'm trying to access a MongoDB collection from a java code to be 'eval' by BSF.
> I tried configure the MongoDB connection in both ways coding the driver connection and following the tutorial [https://mongodb.github.io/mongo-java-driver/3.10/driver/tutorials/jndi/] , but in both cases the same error.
> Below the code to be executed by BSF:
>  
> {code:java}
> import javax.naming.InitialContext;
> import com.mongodb.MongoClient;
> import com.mongodb.client.MongoDatabase;
> import com.mongodb.client.MongoCollection;
> import org.bson.Document;
> InitialContext cxt = new InitialContext();
> if ( cxt == null ) {
>    throw new Exception("Uh oh -- no context!");
> }
> MongoClient ds = (MongoClient) cxt.lookup( "java:/comp/env/mongodb/MongoClient" );
> if ( ds == null ) {
>    throw new Exception("Data source not found!");
> }
> MongoDatabase database = ds.getDatabase("ssp");
> //MongoCollection<Document> collection = database.getCollection("customer");
> {code}
>  
> The code above runs fine, but If I uncomment the last line *MongoCollection<Document> collection = database.getCollection("customer")* , the BSF throw a exception. See the attached *exception.txt* file.
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)