java - Querying mongodb dbref inner field -
i need hide user related data isactive flag set false. there many collection in have used user collection of type dbref (around 14 collections) , each collection contains more 10 million records.
let me explain more of example.
suppose have 2 collections:
- user
- contact
user collection contains following fields:
- firstname (string)
- last name (string)
- isactive (boolean)
contact collection contains following fields:
- contacter (user) declared of type dbref.
- contactee (user) declared of type dbref.
- contactstatus (string)
now want fire query fetch contacts contactstatus = "confirmed" && contacter.isactive = true && contactee.isactive = true
in terms of mongodb, query this:
db.contacts.find({"contactstatus" : "confirmed", "contacter.isactive" : true, "contactee.isactive" : true});
but when run query in mongo shell, returns 0 record.
so question here 1) possible fire query on dbref's inner field ? 2) if not, how can achieve that.
note - @ stage, not able modify data model. of "in" query, can achieve this. increase 1 round trip everywhere need hide user.
currently using mongodb-2.4.5 , spring-data-mongodb-1.2.3 jar
so far code -
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);
yes, can query on dbref fields, not way doing it.
dbref small sub-documents contains 2 fields:
$ref
-the referenced collection
$id
- _id value of document in referenced collection
(actually there third field $db
if reference different db)
so, using shell can ask contacter.$id (which returns object id in users collection) or $ref, can't query on such contract.isactive, field of user, not ref, , shell doesn't fetch user.
if using java driver, both contacter , contactee represented com.mongodb.dbref
has method fetch() retrieve dbobject
(user)
if using spring-data-mongodb, might want have class such as:
class contact { @dbref user contacter; @dbref user contactee; string contactstatus; }
both user objects loaded you
Comments
Post a Comment