MongoDB: query by @DBRef

后端 未结 1 737
说谎
说谎 2021-01-18 12:21

I have a class hierarchy designed for store user notifications:

@Document
public class Notification {
   @Id
   private String id;
   @DBRef
   priv         


        
相关标签:
1条回答
  • 2021-01-18 12:51

    Since you look like you are only querying by _id I believe you can do:

    db.NotificationA.findOne({"tag.$id": ObjectId("blah")});
    

    However:

    But I need to query on the fields of JetAnotherClass (two levels of @DBRef fields).

    DBRefs are not JOINs, they are merely a self describing _id in the event that you do not know the linking collection it will create a helper object so you don't have to code this yourself on the client side.

    You can find more on DBRefs here: http://docs.mongodb.org/manual/applications/database-references/

    Basically you can query the sub fields within the DBRef from the same document, i.e.: DBRef.$_id but you cannot, server-side, resolve that DBRef and query on the resulting fields.

    0 讨论(0)
提交回复
热议问题