Planexecutor error during aggregation :: caused by :: can't convert from bson type object to string

db.persons.aggregate([

{ $project: { _id: 0, name: 1, email: 1, location: { type: “Point”, coordinates: ["$location.coordinates.longitude", “$location.coordinates.latitude”] } } },

{

$project: {

gender: 1, email: 1, location: 1, fullName: {

 $concat: [{ $toUpper: { substrCP: ["$name.first", 0, 1] } },

 { $substrCP: ["name.first", 1, { $subtract: [{ $strLenCP: "$name.first" }, 1] }] },

  " ", { $toUpper: { substrCP: ["$name.last", 0, 1] } },

 { $substrCP: ["name.last", 1, { $subtract: [{ $strLenCP: "$name.last" }, 1] }] }]

}

}

}

]).pretty();




output
planexecutor error during aggregation :: caused by :: can’t convert from bson type object to string
.
.
please Give a solution

It looks like you’re missing the $ in front of substrCP. This is missing in both the first and last name sections. Try changing that and let us know if you have any other issues.

1 Like

thank you so much sir…im a beginner at this so I didn’t know the perfect reason for the error it got solved :slightly_smiling_face:

Glad that worked out for you Puneeth. Keep asking questions as you progress on your journey with MongoDB, and soon you’ll be helping those who are new on the path.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.