[JAVA-2420] Aggregates.replaceRoot and Aggregates.addFields Created: 28/Dec/16  Updated: 27/Oct/23  Resolved: 28/Dec/16

Status: Closed
Project: Java Driver
Component/s: API
Affects Version/s: 3.4.1
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: himnaz Assignee: Unassigned
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows, Java 8



 Description   

Hi I am trying to use Aggregates.replaceRoot and Aggregates.addFields in MongoDb Java Driver in our application. I have the following codes used to test this function which is failing. Can you please tell me if it is a bug or syntax error in my code.

public ArrayList<Document> testAggregation5()

{ MongoCollection<Document> collection = databasePuttPutt.getCollection("Merchant"); return collection.aggregate( Arrays.asList( Aggregates.addFields(new Field("merchantId", "testval")), Aggregates.unwind("$promotion_list"), Aggregates.sort(orderBy(ascending("pro_created_date"))) ) ).into(new ArrayList<Document>()); }

public ArrayList<Document> testAggregation6a()

{ MongoCollection<Document> collection = databasePuttPutt.getCollection("Merchant"); return collection.aggregate( Arrays.asList( Aggregates.replaceRoot("$promotion_list") ) ).into(new ArrayList<Document>()); }

///////////////////////////////////////////////////////////////////////Error Stack is follwos/////////////

Caused by: java.lang.NoSuchMethodError: com.mongodb.client.model.Aggregates.replaceRoot(Ljava/lang/Object;)Lorg/bson/conversions/Bson;
at dbteam.com.jsf.starter.todo.NativeQuery.testAggregation6a(NativeQuery.java:140)
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:497)
at org.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:437)
at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.doMethodInterception(Jsr299BindingsInterceptor.java:82)
at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:93)
at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ejb3.component.invocationmetrics.ExecutionTimeInterceptor.processInvocation(ExecutionTimeInterceptor.java:43)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:437)
at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:64)
at org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:83)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ee.concurrent.ConcurrentContextInterceptor.processInvocation(ConcurrentContextInterceptor.java:45)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:52)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:51)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:275)
... 156 more



 Comments   
Comment by himnaz [ 28/Dec/16 ]

Thanks. You are right.

Comment by Jeffrey Yemin [ 28/Dec/16 ]

It's almost certainly the case that in the JBoss environment in which you are running there is an older version of the driver in the classpath that is taking precedence over the 3.4.1 version with which you compiled those tests. You might try enabling verbose class loading using the -verbose:class VM options to figure out what's happening. For example, when I run your example in a test program with -verbose:class specified on the command line, I see this output:

...
[Loaded com.mongodb.client.model.Aggregates from file:/Users/jeff/.m2/repository/org/mongodb/mongodb-driver-core/3.4.1/mongodb-driver-core-3.4.1.jar]
...

Generated at Thu Feb 08 08:57:10 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.