Welcome to Knowage Q&A, where you can ask questions and receive answers from other members of the community.
0 votes
1 view
I created a new data source for connecting a mongodb collection. parameter (taken from here

http://wiki.spagobi.org/xwiki/bin/view/spagobi_server/data_set#HQueryDataSet28Mongo29)

are

label: myTest

dialect: MongoDB

read and write

jdbc

url: localhost:27017/$cdb  (cdb is the name of collection)

no user and pwd

driver mongo

I test the connection and the answer was "test parameter are correct"

Then I created a new dataset with the following parameters:

label: myDataSet

name: myDataSetName

scope: USER

category: default dataset category

dataset Type: Query

datasource: myTest

then I select "edit script" and here

script language Javascript

script test: var query=db.getCollection('bigColl').find({});

save

and I select the preview function

I recevied the Error

ReferenceError: "db" is not defined

From the knowage.logs file I see

[http-bio-8080-exec-6] 15 ott 2017 23:20:45,282 ERROR it.eng.spagobi.rest.interceptors.RestExceptionMapper.toResponseFromGenericException:97 - Catched service error:

it.eng.spagobi.utilities.exceptions.SpagoBIServiceException: An unexpected error occured while executing dataset: ReferenceError: "db" is not defined

at it.eng.spagobi.tools.dataset.service.ManageDataSetsForREST.getDatasetTestResultList(ManageDataSetsForREST.java:1660)

at it.eng.spagobi.tools.dataset.service.ManageDataSetsForREST.getDataSetResultsAsJSON(ManageDataSetsForREST.java:1608)

at it.eng.spagobi.tools.dataset.service.ManageDataSetsForREST.datatsetTest(ManageDataSetsForREST.java:1573)

at it.eng.spagobi.tools.dataset.service.ManageDataSetsForREST.previewDataset(ManageDataSetsForREST.java:129)

at it.eng.spagobi.api.DataSetPutResource.previewDataSet(DataSetPutResource.java:75)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:167)

at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:257)

at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:222)

at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:211)

at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:542)

at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:524)

at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:126)

at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208)

at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)

at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)

at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)

at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:409)

at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1044)

at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)

at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

at java.lang.Thread.run(Thread.java:745)

Caused by: it.eng.spagobi.utilities.exceptions.SpagoBIRuntimeException: An unexpected error occured while executing script

at it.eng.spagobi.utilities.scripting.SpagoBIScriptManager.runScript(SpagoBIScriptManager.java:101)

at it.eng.spagobi.tools.dataset.common.behaviour.QuerableBehaviour.applyScript(QuerableBehaviour.java:149)

at it.eng.spagobi.tools.dataset.common.behaviour.QuerableBehaviour.getBaseStatement(QuerableBehaviour.java:95)

at it.eng.spagobi.tools.dataset.common.behaviour.QuerableBehaviour.getStatement(QuerableBehaviour.java:67)

at it.eng.spagobi.tools.dataset.bo.ConfigurableDataSet.loadData(ConfigurableDataSet.java:139)

at it.eng.spagobi.tools.dataset.bo.ConfigurableDataSet.test(ConfigurableDataSet.java:241)

at it.eng.spagobi.tools.dataset.service.ManageDataSetsForREST.getDatasetTestResultList(ManageDataSetsForREST.java:1640)

... 38 more

Caused by: javax.script.ScriptException: ReferenceError: "db" is not defined in <eval> at line number 73

at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:467)

at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:451)

at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:403)

at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:399)

at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:155)

at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)

at it.eng.spagobi.utilities.scripting.SpagoBIScriptManager.runScript(SpagoBIScriptManager.java:99)

... 44 more

Caused by: <eval>:73 ReferenceError: "db" is not defined

at jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:57)

at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:319)

at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:291)

at jdk.nashorn.internal.objects.Global.__noSuchProperty__(Global.java:1426)

at jdk.nashorn.internal.scripts.Script$2$\^eval\_.:program(<eval>:73)

at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:637)

at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494)

at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)

at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:446)

... 49 more

any suggestion?
Environment Knowage CE 6.0 on windows 10
in Data Set by (160 points)

1 Answer

0 votes
Hi,

 in the datasource definition in the url you should have the name of the db not the name of the collection..
by (1.1k points)
I tried to use the name of DB instead of the collection name. The test seems to be ok, but when I create the dataset with the same procedure above described I receive the same error...

Notice that no connection to the mongodb server are realized thus knowage did not attempt to connect to mongo server. It seems to me that the internal javascript engine simply did not recognize the mongodb query command

Hi,

 try this 2 ways:

1) remove the dollar from definition of dataosurce localhost:27017/cdb (name of db)

2) instead of getting collection using getCollection write query directly like db.bigCol.findOne()

I try to remove the "$" symbol and change the query..nothing to do....

I'm wondering if is it possibile to use JNDI  instead of jdbc
Hi,

 depends on what is your mongo version.

If you have a recent MongoDB Enterprise you also have the BI Connector (https://www.mongodb.com/products/bi-connector).

That is a daemon you can connect to using a mysql jdbc driver. In this case you can just configure a mysql datasource (jndi) and use MongoDB like it is a mysql db.

The Knowage MongoDB connector is a custom connector taht allows you to use mongdb js language to create the queries. What is the version of mongoDB you have, in thsi way we can schedule a test?
I had the latest version of community edition of Mongo (3.4.9)

thanks
...