0
votes

I get a error. com.mongodb.MongoCommandException: Command failed with error 16007 (Location16007): 'can't convert from BSON type object to String' on server 10.3.87.54:27017. The full response is { "ok" : 0.0, "errmsg" : "can't convert from BSON type object to String", "code" : 16007, "codeName" : "Location16007" }

{ "$project" : { "ss" : "$movieId", "dd" : "$title", "t" : { "$substr" : [{ "SUBSTR_fa81ecc633086358d21e299e466533bb" : { "$substr" : ["genres", 1, 8] } }, 1, 6] } } }

image is here

1
What are you trying to achieve with this $project? Can you attach any example here?Akash
I want to achieve SQL to mongodb,like "select substring(substring(title,1,8)1,6) from a"ighack

1 Answers

0
votes

Try this:

{ $project : { ss : "$movieId", dd : "$title", t : {$substr : [{$substr : ["$genres", 1, 8]}, 1, 6] } } }

If this doesn't work, paste your document structure & expected outcome.