I need to hide all the user related data whose isActive flag is set to false. There are many collection in which I have used user collection as of type DBRef (around 14 collections) and each collection contains more than 10 million records.
Let me explain it more properly with help of example.
Suppose I have two collections:
- User
- Contact
User collection contains following fields:
- Firstname (String)
- Last Name (String)
- isActive (Boolean)
Contact collection contains following fields:
- Contacter (User) Declared as of type DBref.
- Contactee (User) Declared as of type DBRef.
- ContactStatus (String)
Now I want to fire a query which will fetch all the contacts whose
ContactStatus = "Confirmed" && Contacter.isActive = true && Contactee.isActive = true
In terms of mongodb, the query will be something like this:
db.Contacts.find({"ContactStatus" : "Confirmed", "Contacter.isActive" : true, "Contactee.isActive" : true});
But when I run this query in mongo shell, it always returns a zero record.
So the question here is 1) Is it possible to fire a query on the DBRef's inner field ? 2) If not, then how can I achieve that.
Note - At this stage, I am not able to modify my data model. With the help of "in" query, I can achieve this. But it will ultimately increase one round trip everywhere where I need to hide that user.
Currently I am using mongodb-2.4.5 and Spring-Data-MongoDB-1.2.3 jar
So far my code is like this -
Criteria criteria = new Criteria();
criteria = criteria.where(Contact.CONTACT_REQUEST_STATUS).is(ContactRequestStatusEnum.ACCEPTED);
criteria = criteria.and(Contact.CONTACTER + "." + User.ACTIVE).is(Boolean.TRUE);
criteria = criteria.and(Contact.CONTACTEE + "." + User.ACTIVE).is(Boolean.TRUE);
Query q = new Query(criteria);
List<Contact> contacts = Contacts.find(q, Contact.class);