0

I have a query:

db.results.aggregate([{
        $project: {
            "_id": {
                $toString: "$_id"
            }
        }
    }
]);

I need to convert this into java springboot aggregation. I'm confused with $toString in java.

Any idea?

3
  • please paste your aggregation code. Also, ObjectId.toString() ? Commented Jan 29, 2020 at 11:31
  • Change $project to $addFields. Commented Feb 5, 2020 at 13:15
  • how $addFields will work? Commented Apr 21, 2020 at 18:35

1 Answer 1

2

In Spring aggregation you need to use like below which give a String value of ObjectId:

ProjectionOperation projectOp = Aggregation.project().andArrayOf(new Document("$toString","$_id")).as("id");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.