0

I'm trying to do a status update to a set of records in one collection where an ID exists in a different collection.

I cannot think how you would construct such a query, I believe I would add it into a finaAndModify function as shown below.

The jist of what I'm trying to do is:

SELECT records in db.raw_originBusinessData WHERE objectCycle_ID EXISTS in db.std_sourceBusinessData.

Here's the script which I am trying to complete, if findAndModify is the wrong method, please let me know, much appreciated.

db.std_sourceBusinessData.findAndModify({
  query: { ? },
  update: { $objectStatus: { $literal: "PROCESSED" } },
})
Matt Lightbourn
  • 597
  • 3
  • 20

1 Answers1

0

As far as I know, what you're suggesting isn't possible because

MongoDB does not support joins

From: https://docs.mongodb.org/ecosystem/tutorial/model-data-for-ruby-on-rails/

and findAndModify works within a collection. See: https://docs.mongodb.org/v3.0/reference/method/db.collection.findAndModify/

You could either do this within your application code through two queries, using the result of the first to make the second

OR

You could denormalize your data, saving the ids you need in each document/row in the collection.

Shreyans
  • 871
  • 7
  • 20
  • Thanks for your response, I don't believe I am trying to do a join, 'simply' check that a reference in one collection exists in another. Is there no way to create a query across two collections? Thanks – Matt Lightbourn Dec 15 '15 at 21:38
  • Ah ok, so it's looks like I need to create a document which looks up the unique objectCycleIDs in an array and $out to the collection where I want to run an update where I can do a query for all documents where objectCycleID matches one of the ones in the array of the 'temporary' document. Am I on the right track here? If so, I will need to raise a different question in here for the query part. Thanks, Matt – Matt Lightbourn Dec 15 '15 at 22:04