seedscoder
V2EX  ›  问与答

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

  •  
  •   seedscoder · Mar 11, 2022 · 1593 views
    This topic created in 1541 days ago, the information mentioned may be changed or developed.

    我想在 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 replies    2022-03-11 21:43:22 +08:00
    fmumu
        1
    fmumu  
       Mar 11, 2022
    不知道你的需求是啥,评论回复记录应该有个主贴记录字段吧
    评论少就全塞在一条记录 json 搞定,
    再多一点就根据主贴记录全查出来程序递归
    真的很多就懒加载呗
    https://www.mongodb.com/blog/post/6-rules-of-thumb-for-mongodb-schema-design-part-1
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2923 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 08:14 · PVG 16:14 · LAX 01:14 · JFK 04:14
    ♥ Do have faith in what you're doing.