Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for dateToString expression #879

Closed
parvanov opened this issue Jan 7, 2016 · 2 comments
Closed

add support for dateToString expression #879

parvanov opened this issue Jan 7, 2016 · 2 comments

Comments

@parvanov
Copy link

parvanov commented Jan 7, 2016

There's no way currently to use $dateToString aggregation operator.

Projection.expression wraps all arguments as a list while dateToString expects a single object as argument.

I have tried all 3 examples bellow and all of them fail with the same exception:

DBObject format = new BasicDBObject("format", "%Y-%m-%d");
format.put("date", "$t");

Object format = new Object(){
public String format = "%Y-%m-%d";
public String date = "$t";
};

Object format = "{"format": "%Y-%m-%d", "date": "$t"}";

...
.project(projection("t", expression("$dateToString", format)))

Results in:

com.mongodb.MongoCommandException: Command failed with error 18629: '$dateToString only supports an object as its argument' on server localhost:27018. The full response is { "ok" : 0.0, "errmsg" : "$dateToString only supports an object as its argument", "code" : 18629 }
at com.mongodb.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:86)
at com.mongodb.connection.CommandProtocol.execute(CommandProtocol.java:119)
at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:159)
at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:286)
at com.mongodb.connection.DefaultServerConnection.command(DefaultServerConnection.java:173)
at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:215)
at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:206)
at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:112)
at com.mongodb.operation.AggregateOperation$1.call(AggregateOperation.java:227)
at com.mongodb.operation.AggregateOperation$1.call(AggregateOperation.java:223)
at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:239)
at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:212)
at com.mongodb.operation.AggregateOperation.execute(AggregateOperation.java:223)
at com.mongodb.operation.AggregateOperation.execute(AggregateOperation.java:65)
at com.mongodb.Mongo.execute(Mongo.java:773)
at com.mongodb.Mongo$2.execute(Mongo.java:760)
at com.mongodb.DBCollection.aggregate(DBCollection.java:1377)
at com.mongodb.DBCollection.aggregate(DBCollection.java:1347)
at org.mongodb.morphia.aggregation.AggregationPipelineImpl.aggregate(AggregationPipelineImpl.java:230)
at org.mongodb.morphia.aggregation.AggregationPipelineImpl.aggregate(AggregationPipelineImpl.java:222)
at org.mongodb.morphia.aggregation.AggregationPipelineImpl.aggregate(AggregationPipelineImpl.java:212)

@parvanov
Copy link
Author

Also the $let expression takes an object.

@evanchooly
Copy link
Member

This feels like a second issue. If so, please open a new one so it can be tracked properly. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants