3

When I am converting MongoDB UUID to string in MongoDB projection query using $toString, its giving the following error: "Unsupported conversion from binData to string in $convert with no onError value"

Can anyone suggest a solution, please?

db.collection.aggregate([
  {
    $project: {
      _id: {
        $toString: "$_id"
      }
    }
  }
])
Ramakant Shukla
  • 137
  • 1
  • 10
  • 1
    What version of MongoDB are you using? your query perfectly works for me. More reference https://stackoverflow.com/questions/36059986/how-to-project-objectid-to-string-value-in-mongodb-aggregate?rq=1 – Mani Mar 11 '19 at 18:36
  • I am using MongoDB 4.0.6 version. – Ramakant Shukla Mar 12 '19 at 20:02
  • I was tried this solution, but not able to figure out is implementation inside the MongoDB aggregation query. Moreover, I need to convert UUID to string using MongoDB aggregation query – Ramakant Shukla Mar 12 '19 at 20:31
  • Any particular reason to convert UUID to string? – Mani Mar 12 '19 at 20:32
  • Its needed for angular web application transactions with MongoDB using Asp.Net core web API. – Ramakant Shukla Mar 12 '19 at 20:42
  • 1
    I think you'll need to convert your UUIDs to strings outside of your aggregation query. It's just binary data to MongoDB. – JohnnyHK Mar 13 '19 at 13:49
  • @RamakantShukla Try converting UUID string in C# code. – Mani Mar 13 '19 at 20:40

0 Answers0