Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

290
Views
Replace string in one node of Mongodb document

I need your help to write one replace query. I have connected one third party software mongodb. I am SQL guy and not able to write query of replace specific node value.

I am using Robo 3T software. Below is one record json from the document.

{
    "_id" : ObjectId("6036c343445f3640c53e0a"), 
    "shares" : [ 
        {
            "shareId" : ObjectId("6035cc6acf345f3640c53d1a"),
            "type" : "user"
        }, 
        {
            "shareId" : ObjectId("6035b536cf345f3640c53cae"),
            "type" : "group",
            "rule" : "view",
            "subscribe" : false
        }
    ],
    "tags" : [],
    "lastUsed" : ISODate("2021-03-09T16:51:30.059Z"),
    "usageCount" : 1,
    "layout" : {
       too many values with multiple node.
    },
    "instanceType" : "owner",
    "original" : null,
    "editing" : true,
    "filters" : [ 
        {
            "jaql" : {
                "table" : "Xyz",
                "column" : "title",
                **"dim" : "[dbo.ketan.Title]",**
                }
            }
            "disabled" : false
        }, 
        {
            "jaql" : {
                "table" : "abc",
                "column" : "name",
                **"dim" : "[dbo.ketan.name]",**
                "datatype" : "text",
                "merged" : true,
                "title" : "Inventor Name",
                "filter" : {
                    "explicit" : false,
                    "multiSelection" : true,
                    "all" : true
                },
                "collapsed" : false
            },
            "instanceid" : "1B1E4-F6DC-28",
            "isCascading" : false
        }, 
        
}

Here I want to replace "dim" : "[dbo.ketan.name]", to "dim" : "[kiran.name]",

Can you please help me to write query ?

This is my first post. The Writing may be not up to mark. Please let me know if you need any more details.

Thank you.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

This is how you can acheive the functionality. Although your MongoDB Version should be >= 3.6

db.collection.update(                                     //collection
  {"filters.jaql.dim": {"$regex": "dbo.ketan"}},          //update filter
  {"$set": {"filters.$[elem].jaql.dim": "[kiran.name]"}}, //update action
  {
    "arrayFilters": [
      {
        "elem.jaql.dim": {
          "$regex": "dbo.ketan"
        }
      }],
    "multi": true
  }                                               //filters for all element to be updated
)

To see this logic in action: MongoPlayground Example

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!