MongoDB Solr search to get document links in one search query

I have two or more collections in mongodb that are replicated to solr indexes using mongo-solr connectors. For the sake of explaining my problem I ran into, let's take a traditional employee and department example (I know this is a DB oriented document and I can embed a department in an employee document, but please let me explain my question with this trivial example):

Employee document:

   "_id": ObjectId(..),
   "firstName": "John",
   "lastName": "David",
   "departMent": ObjectId(..) - a DBRef for department document


Department document:

  "_id": ObjectId(..),
  "departmentName": "Marketing"


Let's say that the above two documents are linked in an employee document using the ref department object id. Now the mongo-solr connector has replicated these structures as they are, and let all fields be indexed and persisted.

Now here's my question (and problem):

If I search for the solr index by employee firstName (or lastName), I must return the results in such a way that the solr search query must include the name "departmentName" instead of the ObjectId Department reference, and that this must occur during a single search query originating from the client.

How can I do this using Solr apis?

Thanks in advance.


source to share

1 answer

The ideal solution, of course (from Solr's point of view), would be to store the data in Solr in a denormalized form. However, if this is not a viable option, you might want to take a look at Parser.

You are running the query line by line (not tested):

q={!join from=department to=departmentName}lastName:David AND departmentName:Marketing




All Articles