开发者

Doctrine MongoDB query embedded documents

开发者 https://www.devze.com 2023-03-20 17:58 出处:网络
I开发者_高级运维 have top-level document User with embedded Keyword documents (User EmbedMany Keyword).

I开发者_高级运维 have top-level document User with embedded Keyword documents (User EmbedMany Keyword). Well i don't know how to get Keyword object from concrete User by Keyword's id I spent a lot of time trying to solve this but it still open problem for me. So i help someone here will help me. Thanks a lot.


You can load only parent document from the mongodb. But there is $slice operator that can load parent document just with limited number of embedded documents.

On native mongodb language you can do it so:

db.users.find({_id: "UserId", "Keywords._id", "keywordId"},
               {Keywords:{$slice: 1}}) // first matched by id keyword

From doctrine you will receive user document with only one embedded keyword.

Hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消