Mass changing link inside mongodb

Unsolved Technical Support
  • Hi,

    I have to change the domain name of my forum. This render internal links (within posts) broken.

    My mongodb version is 3.2.11

    I have tried the following db script:

    db.collection.updateMany(
      { "objects.content": { $regex: /old.domain.com/ } },
      [{
        $set: { "objects.content": {
          $replaceOne: { input: "$objects.content", find: "old.domain.com", replacement: "new.domain.com" }
        }}
      }]
    )
    

    Which lead me to the following error:

    2022-06-09T17:24:23.808+0200 E QUERY    [thread1] Error: the update operation document must contain atomic operators :
    DBCo[email protected]/mongo/shell/crud_api.js:568:1
    

    I greatly appreciate if someone could point me how to achieve that.

    PS: I am totally illiterate in mongodb.

    Thank you all

  • Or make this in nginx

    ### OLD_FORUM
    
    server {
            listen 80;
            listen 443;
            server_name  old_domain.com
            # SSL Certificate
            ssl_certificate      /etc/letsencrypt/live/old_domain.com/fullc>
            ssl_certificate_key  /etc/letsencrypt/live/old_domain.com/privk>
            ssl_dhparam /etc/ssl/nginx/dhparam-2048.pem;   
            return 301 $scheme://new_forumdomain.com$request_uri;
    }
    
  • @FrankM
    Sorry but this does not work at all.
    How can a redirection be applied from a webserver that does not recieve the request.

    I don't have the old domain anymore, and even I'd have it now, This does not address the issue on the long run.

  • @doekia Does this help ?


Suggested Topics