【问题标题】:How to write $substr($substr(a,1,8),1,6) with java in mongodb如何在mongodb中用java编写$substr($substr(a,1,8),1,6)
【发布时间】:2019-01-21 07:06:00
【问题描述】:

我得到一个错误。 com.mongodb.MongoCommandException:命令失败,出现错误 16007(Location16007):服务器 10.3.87.54:27017 上的“无法从 BSON 类型对象转换为字符串”。完整的响应是 { "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”: [“流派”, 1, 8] } }, 1, 6] } } }

image is here

【问题讨论】:

  • 你想通过这个 $project 实现什么目标?你能在这里附上任何例子吗?
  • 我想实现SQL到mongodb,比如"select substring(substring(title,1,8)1,6) from a"

标签: mongodb


【解决方案1】:

试试这个:

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

如果这不起作用,请粘贴您的文档结构和预期结果。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-11
    • 2019-08-03
    • 2015-08-30
    • 2015-04-19
    相关资源
    最近更新 更多