2

I have a collection with objects with a json output like this:

{
  "_id": {
    "$oid": "53107ed2e6fb449fa641b903"
  },
  "title": "myBook"
}

But I would like to get this:

{
  "_id": "53107ed2e6fb449fa641b903",
  "title": "myBook"
}

I have tried with dot notation and $project but it doesn't work:

db.books.aggregate({
  $project: {
    _id: "$_id.oid",
    title: 1 
  }
)
Fran b
  • 3,016
  • 6
  • 38
  • 65

1 Answers1

1

Looks like your aggregate query syntax is incorrect. Try this:

db.books.aggregate([{$project:{_id:"$_id.oid", title:1}}])

Also, in the input json, you have a '$' prefix for the oid (i.e, "$oid"). That's illegal in MongoDB.

Anand Jayabalan
  • 12,294
  • 5
  • 41
  • 52