1

I have several collections within the same database: assessments_1, assessments_2, assessments_3, assessments_4 ect Each of the collections has an existing fields titled "test_name" and "vendor". When vendor = "Bridge" and test_name = "Tabulation", I would like to concat "EM - " to the beginning of the test_name field so it becomes "EM - Tabulation".

I've looked though the mongoDB manual on concat, but there are no references to update across collections.

I'm on MongoDB 4.4.4. Using Studio3T.

rickhg12hs
  • 10,638
  • 6
  • 24
  • 42
Jake
  • 173
  • 1
  • 2
  • 16
  • What have you tried so far? The update itself is trivial. You just need to repeat it once per collection. – ray Jan 31 '23 at 04:05
  • I am in the process of updating each of the 45 collections manually. There are actually 15 test names to concat the "EM -" to. I simplified the details for the question. If I could list the collections and then cycle through each of the fields, that would save me quite a bit of work. I figure I can also just use something like this: { $or : [ { "test_name" : "Tabulation" }, { "test_name" : "Timing" } ], "vendor" : "Bridge" } – Jake Jan 31 '23 at 04:14
  • Rather than `"$or"`, you could use `"test_name": {"$in": ["Tabulation", "Timing", ...]}`. – rickhg12hs Jan 31 '23 at 04:22
  • The scenario seems weird to me. If the documents in these collections share similar schemas, you should consider putting them in the same collection instead of putting them in many similar collections with similar naming – ray Jan 31 '23 at 04:25

0 Answers0