Yes, you can query on the DbRef fields, but not the way you are doing it.
DbRef is a small sub-documents which contains two fields:
$ref
-the referenced collection
$id
- the _id value of a document in that referenced collection
(actually there is a third field $db
if the reference is to a different db)
So, using the shell you can only ask for contacter.$id (which returns the Object id in users collection) or $ref, but you can't query on something such as contract.isActive, as this is a field of the user, not the Ref, and the shell doesn't fetch the user.
If you are using java driver, both Contacter and Contactee are represented as com.mongodb.DBRef
which has a method fetch() to retrieve the DBObject
(user)
If using spring-data-mongodb, you might want to have class such as:
class Contact {
@DBRef
User contacter;
@DBRef
User contactee;
String contactStatus;
}
Both user objects will be loaded for you