相关文章推荐

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MongoDB supports DbRef fields when one document needs to refer to another in a standard way -- see http://www.mongodb.org/display/DOCS/Database+References .

It would be really excellent if QueryDSL could support doing queries where fields that represented DbRefs were automatically traversed during a query. For example (using the Spring Data Mongodb annotations):

@Document
Obj1 {
  @DbRef Obj2 obj2Ref;
@Document
Obj2 {
  String foo;

then one could do the following query:

 query
    .where(QObj1.obj2Ref.foo.eq("Bob"))
    .list()
          

This sounds like a valid addition, but might be quite difficult to implement, since dbref on database level doesn't seem to be supported.

So it's multiple nested queries or maybe map-reduce. Do you see other implementation options?

Here I'd also prefer to apply some more explicit joining

query.join(doc.obj2Ref, obj2).on(obj2.foo.eq("Bob"))

This could be continued with a where-clause if additional constraints are needed. This separates the query layers quite clearly. Is something like this ok?

public void Double2() { assertEquals("Mike", where() .join(user.friend(), friend).on(friend.firstName.eq("Mary")) .join(user.enemy(), enemy).on(enemy.firstName.eq("Ann")) .singleResult().getFirstName()); @Test public void Deep() { // Mike -> Mary -> Jane assertEquals("Mike", where() .join(user.friend(), friend).on(friend.firstName.isNotNull()) .join(friend.friend(), friend2).on(friend2.firstName.eq("Jane")) .singleResult().getFirstName());

i would like to do the same with list of @DBRef like this :

@DBRef
private List<FileSys> registeredChannels = new ArrayList<FileSys>();

my request > QProfile.profile.registeredChannels.contains(channel)

(channel is an FileSys object)

always return an empty list

please, help me

@timowest I haven't had a chance to try out the new feature yet... however FYI the spring-data mongodb guys are thinking about how to use this from the spring-data mongodb querydsl integration. You might have some useful thoughts on it...

https://jira.springsource.org/browse/DATAMONGO-362

@timowest is there a possibility to construct query with OR between join predicates?

public class Car {
    BigInteger id;
    String name;
    @DBRef
    Engine engine;
    @DBRef
    Radio radio;
public class Radio {
    BigInteger id;
    Boolean rds;
public class Engine {
    BigInteger id;
    Integer power;

And I would like to get cars with engine more then 100 power or cars with radios with rds.

 
推荐文章