推荐工具
RoboMongo
推荐书目
50 Tips and Tricks for MongoDB Developers
Related Blogs
Snail in a Turtleneck
gancl
V2EX  ›  MongoDB

mongoose 怎么 populate 别的集合的子文档?

  •  1
     
  •   gancl · Jun 13, 2014 · 5253 views
    This topic created in 4369 days ago, the information mentioned may be changed or developed.

    I can't find it with populate, o.B is a objectId,o.B.name is undefined.

    BSchema is a subdocument of ASchema, CSchema has a ref connection of BSchema.

    I want to find all CSchema which CSchema's name is "c_xxx", and shows CSchema's B's name and its A's name.

    Like this result: {CName:"c_xxx",BName:"b_xxx",AName:"a_xxx"}
    2 replies    2014-06-13 23:21:27 +08:00
    shuson
        1
    shuson  
       Jun 13, 2014
    when populate fields, it only works if there is ref to children from the parent schema
    gancl
        2
    gancl  
    OP
       Jun 13, 2014
    @shuson 看来这种情况用不了populate,只能手动一条条查了.
    怎么等待CSchema.find({ 执行完毕? 我再手动将结果构造成json
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2577 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 11:42 · PVG 19:42 · LAX 04:42 · JFK 07:42
    ♥ Do have faith in what you're doing.