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:

  1. user
  2. contact

user collection contains following fields:

  1. firstname (string)
  2. last name (string)
  3. isactive (boolean)

contact collection contains following fields:

  1. contacter (user) declared of type dbref.
  2. contactee (user) declared of type dbref.
  3. 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

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -