V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
seedscoder
V2EX  ›  问与答

MongoDB 有和 Mybatis collections 相同效果的查询方式么?

  •  
  •   seedscoder · 2022-03-11 07:36:04 +08:00 · 750 次点击
    这是一个创建于 770 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我想在 MongoDB 中实现如下效果(递归查询子节点),可以实现么?

    多层级,我想一次性递归查询子节点

    用 MongoDB 实现评论和回复存储,schema 优雅的设计应该是怎样的,我想着通过 parentId 和 id 关联

    
    <resultMap id="xxx" type="xxxx">
        <id column="id" jdbcType="BIGINT" property="id" />
        <result column="name" jdbcType="VARCHAR" property="name" />
        <result column="pid" jdbcType="BIGINT" property="name" />
        <collection property="children"  column="id" ofType="xxx" select="selectSubItemByPid"/>
    </resultMap>
     
    
    <select id="selectSubItemByPid" parameterType="xxx" resultMap="xxx">
    	select * from xxx where pid = #{pid}
    </select>
    
    
    1 条回复    2022-03-11 21:43:22 +08:00
    fmumu
        1
    fmumu  
       2022-03-11 21:43:22 +08:00
    不知道你的需求是啥,评论回复记录应该有个主贴记录字段吧
    评论少就全塞在一条记录 json 搞定,
    再多一点就根据主贴记录全查出来程序递归
    真的很多就懒加载呗
    https://www.mongodb.com/blog/post/6-rules-of-thumb-for-mongodb-schema-design-part-1
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5610 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 06:12 · PVG 14:12 · LAX 23:12 · JFK 02:12
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.