开发者

Multiple search in mongodb with morphia

开发者 https://www.devze.com 2023-04-12 00:53 出处:网络
I\'ve two classes: User and Project. The project class have ONE user (the owner of project). In search method, it returns a list of user after a method, and with this list of users,

I've two classes: User and Project. The project class have ONE user (the owner of project).

In search method, it returns a list of user after a method, and with this list of users, i need to find all projects that contains the user of one item of the list os users that i have.

For solve this, i put a for and i call the find (morphia basicDao find method) for each user in for iteration, and t开发者_如何学编程he result i added in a array, and manually i remove the duplicated projects.

Someone knows a better method to solve my problemn? Maybe a morphia method that do this for me...

Sorry for bad english. :)


You can use the $in operator, which is documented online. As you might expect, Morphia's equivalent is called in, too.

Here's an example of using in:

List<String> userList;
List<Project> projects = Project.find().field("user").in(userList).asList();
0

精彩评论

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

关注公众号