mongodb - spring data mongo使用@DBRef,怎么查询指定字段的集合
高洛峰
高洛峰 2017-04-28 09:06:08
0
3
795

我需要查询Archive表,获取Archive.title和User.name字段的结果集(按需),请问可以怎么操作?没找到答案,请指点一二,谢谢!

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(3)
伊谢尔伦

Mongodb does not support join, and your dbref is not in lazy loading mode, so when checking the archive, the user will also be found.
You can use query statements such as hibernate's hsql to implement archive.title and archive.user, but you cannot query aechive.user.name alone.
Mongodb is a non-relational database, which encourages field redundancy and query redundancy, so the situation you mentioned is really difficult to implement

某草草
    @Query(value = "{'id':?0, 'disabled':false}", fields = "{'$id':1, 'success_ret_codes':1}")
    Stream findSuccessRetCodes(String streamId);

Using the fields above, only one field can be missing, and the other fields are null.
But the data of the joint table cannot be queried, because the Archive table stores the ID and table name of the joint table, so only the ID can be found here. , I tested it and directly checked the name of the joint table and reported an error. So, that’s it.

刘奇

I encountered the same problem as you. I haven’t found a way to get only some fields in some DBRef objects. Same solution.
For your problem, you can try the method in this article. My problem is a little more complicated than yours:
http://blog.csdn.net/congcong...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template