how to get mongodb current featureCompatibilityVersion into a variable with only version



  • how to get mongodb current featureCompatibilityVersion into a variable with only version

    instead of printing like this

    db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )
    { "featureCompatibilityVersion" : { "version" : "4.0" }, "ok" : 1 }
    

    Assign only version to a variable using mongo shell

    fcv_version=$(eval "mongo  --eval '')
    echo $fcv_version
    4.0
    


  • Put that answer to variable and then read only wanted value:

    cont:PRIMARY> var h=db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )
    cont:PRIMARY> h.featureCompatibilityVersion.version
    4.4
    

    At your requested form:

    [mongodb_node ~]$ m_ver=$(mongo --quiet --eval 'db.adminCommand({ getParameter: 1, featureCompatibilityVersion: 1 }).featureCompatibilityVersion.version')
    [mongodb_node ~]$ echo $m_ver
    4.4
    

Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2