Details
-
Task
-
Resolution: Works as Designed
-
Major - P3
-
None
-
None
-
None
-
None
Description
MongoDatabase database = client.getDatabase("EDelivery"); |
MongoCollection<Document> collection = database.getCollection("PackageGroup"); |
Block<Document> processBlock = new Block<Document>() { |
@Override |
public void apply(final Document document) { |
System.out.println(document);
|
}
|
};
|
List<? extends Bson> pipeline = Arrays.asList( |
new Document(). |
append("$match", new Document().append("GroupId", "234524")), |
new Document(). |
append("$unwind", new Document().append("path", "$Packages")), |
new Document(). |
append("$match", new Document().append("Packages._id", "e3adda7b-68e6-4b5c-81d1-5af6cf4a8571")), |
new Document(). |
append("$project", new Document().append("SecurityToken", "$Packages.SecurityToken"))); |
|
|
collection.aggregate(pipeline)
|
.allowDiskUse(false) |
.forEach(processBlock);
|
}
|
I'm able to execute Aggregation through Mongo shell however through Java driver I'm not able to
Here is the code and error using 3.8.1 version of java driver.
Error:
|
|
|
Aug 30, 2018 4:29:30 PM com.mongodb.diagnostics.logging.JULLogger logAug 30, 2018 4:29:30 PM com.mongodb.diagnostics.logging.JULLogger logINFO: Opened connection [connectionId\\{localValue:2, serverValue:1012}] to ef1vmongodb3001.dco.elmae:27019Aug 30, 2018 4:29:30 PM com.mongodb.diagnostics.logging.JULLogger logINFO: Closed connection [connectionId\\{localValue:2, serverValue:1012}] to ef1vmongodb3001.dco.elmae:27019 because the pool has been closed.com.mongodb.MongoCommandException: Command failed with error 13: 'not authorized on EDelivery to execute command { aggregate: "PackageGroup", pipeline: [ { $match:
|
|
|
{ GroupId: "234524" }
|
|
|
}, { $unwind:
|
|
|
{ path: "$Packages" }
|
|
|
}, { $match:
|
|
|
{ Packages._id: "e3adda7b-68e6-4b5c-81d1-5af6cf4a8571" }
|
|
|
}, { $project:
|
|
|
{ SecurityToken: "$Packages.SecurityToken" }
|
|
|
} ], cursor: {}, allowDiskUse: false }' on server ef1vmongodb3001.dco.elmae:27019. The full response is { "ok" : 0.0, "errmsg" : "not authorized on EDelivery to execute command { aggregate: \"PackageGroup\", pipeline: [ { $match:
|
|
|
{ GroupId: \"234524" }
|
|
|
}, { $unwind:
|
|
|
{ path: \"$Packages\" }
|
|
|
}, { $match:
|
|
|
{ Packages._id: \"e3adda7b-68e6-4b5c-81d1-5af6cf4a8571\" }
|
|
|
}, { $project:
|
|
|
{ SecurityToken: \"$Packages.SecurityToken\" }
|
|
|
} ], cursor: {}, allowDiskUse: false }", "code" : 13 } at com.mongodb.internal.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:179) at com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:293) at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:255) at com.mongodb.internal.connection.UsageTrackingInternalConnection.sendAndReceive(UsageTrackingInternalConnection.java:99) at com.mongodb.internal.connection.DefaultConnectionPool$PooledConnection.sendAndReceive(DefaultConnectionPool.java:444) at com.mongodb.internal.connection.CommandProtocolImpl.execute(CommandProtocolImpl.java:72) at com.mongodb.internal.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:200) at com.mongodb.internal.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:269) at com.mongodb.internal.connection.DefaultServerConnection.command(DefaultServerConnection.java:131) at com.mongodb.internal.connection.DefaultServerConnection.command(DefaultServerConnection.java:123) at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:242) at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:233) at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:136) at com.mongodb.operation.AggregateOperationImpl$1.call(AggregateOperationImpl.java:193) at com.mongodb.operation.AggregateOperationImpl$1.call(AggregateOperationImpl.java:189) at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:457) at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:401) at com.mongodb.operation.AggregateOperationImpl.execute(AggregateOperationImpl.java:189) at com.mongodb.operation.AggregateOperation.execute(AggregateOperation.java:294) at com.mongodb.operation.AggregateOperation.execute(AggregateOperation.java:41) at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:179) at com.mongodb.client.internal.MongoIterableImpl.execute(MongoIterableImpl.java:132) at com.mongodb.client.internal.MongoIterableImpl.iterator(MongoIterableImpl.java:86) at com.mongodb.client.internal.MongoIterableImpl.forEach(MongoIterableImpl.java:110) at net.codejava.mongodb.JavaMongoDBConnection.main(JavaMongoDBConnection.java:107)
|
|