<p>I have set up the Kubernetes MongoDB operator according to this guide: <a href="https://adamtheautomator.com/mongodb-kubernetes/" rel="nofollow noreferrer">https://adamtheautomator.com/mongodb-kubernetes/</a> and it works well. However, when I try to update the MongoDB version to 6.0.4, I get the following error:</p>
<pre><code>{
&quot;error&quot;:&quot;UPGRADE PROBLEM: Found an invalid featureCompatibilityVersion document (ERROR: 
Location4926900: Invalid featureCompatibilityVersion document in admin.system.version: 
{ _id: \&quot;featureCompatibilityVersion\&quot;, version: \&quot;4.4\&quot; }. 
See https://docs.mongodb.com/master/release-notes/5.0-compatibility/#feature-compatibility. 
:: caused by :: Invalid feature compatibility version value, expected '5.0' or '5.3' or '6.0. 
See https://docs.mongodb.com/master/release-notes/5.0-compatibility/#feature-compatibility.). 
If the current featureCompatibilityVersion is below 5.0, see the documentation on upgrading at
 https://docs.mongodb.com/master/release-notes/5.0/#upgrade-procedures.&quot;}
</code></pre>
<p>I have followed this guide: <a href="https://github.com/mongodb/mongodb-kubernetes-operator/blob/master/docs/deploy-configure.md#upgrade-your-mongodbcommunity-resource-version-and-feature-compatibility-version" rel="nofollow noreferrer">https://github.com/mongodb/mongodb-kubernetes-operator/blob/master/docs/deploy-configure.md#upgrade-your-mongodbcommunity-resource-version-and-feature-compatibility-version</a></p>
<p>This means that my <code>config/samples/arbitrary_statefulset_configuration/mongodb.com_v1_hostpath.yaml</code> file looks like this:</p>
<pre><code>apiVersion: mongodbcommunity.mongodb.com/v1
kind: MongoDBCommunity
metadata:
  name: mdb0
spec:
  members: 2
  type: ReplicaSet
  version: &quot;6.0.4&quot;
  featureCompatibilityVersion: &quot;6.0&quot;
  security:
    ...
</code></pre>
<p>The rest is set according to the linked guide (in the first link above).</p>
<p>The error that is thrown suggests that, for whatever reason, the <code>featureCompatibilityVersion</code> field is ignored, even though I have explicitly set it to <code>&quot;6.0&quot;</code>. However, since the documentation clearly states that this is a possible configuration, this shouldn't be the case. My question then is: am I doing something wrong, or is this a bug?</p>

<p>After a couple of days' research, I managed to find a way to do this, and it is annoyingly simple...</p>
<p>The key to all of this lies in the documentation <a href="https://www.mongodb.com/docs/manual/reference/command/setFeatureCompatibilityVersion/#default-values" rel="nofollow noreferrer">here</a>. Basically, in order to update from mongo 4.4.0 to 6.0.4, you need to do it in steps:</p>
<p>First, change the mongo version from &quot;4.4.0&quot; to e.g. &quot;5.0.4&quot;, whilst setting the featureCompatibilityVersion to &quot;5.0&quot;:</p>
<pre><code>apiVersion: mongodbcommunity.mongodb.com/v1
kind: MongoDBCommunity
metadata:
  name: mdb0
spec:
  version: &quot;5.0.4&quot;
  featureCompatibilityVersion: &quot;5.0&quot;
...
</code></pre>
<p>After having applied this, verify that the featureCompatibilityVersion is indeed 5.0 and that all MongoDB pods are &quot;5.0.4&quot;. If the MongoDB pods aren't &quot;5.0.4&quot;, you need to restart the service (See &quot;<strong>Restarting everything</strong>&quot; below). You can now run the second step:</p>
<p>Update the mongo version to &quot;6.0.4&quot; and the featureCompatibilityVersion to &quot;6.0&quot;:</p>
<pre><code>apiVersion: mongodbcommunity.mongodb.com/v1
kind: MongoDBCommunity
metadata:
  name: mdb0
spec:
  version: &quot;6.0.4&quot;
  featureCompatibilityVersion: &quot;6.0&quot;
...
</code></pre>
<p>Apply this change and verify that the featureCompatibilityVersion is indeed 6.0, and that all MongoDB pods are &quot;6.0.4&quot;. Once again, if the pods aren't &quot;6.0.4&quot;, <strong>Restart everything</strong> according to the procedure below.</p>
<hr />
<h3>Checking feature compatibility version</h3>
The easiest way to do this is to:
<ol>
<li>Port-forward the mongodb connection to your host: <code>kubectl port-forward service/mdb0-svc -n mongodb 27017:27017</code> (according to the guide).</li>
<li>Install mongosh on your host (if you haven't done so already).</li>
<li>Run the following query: <code>mongosh -u mongoadmin -p secretpassword --eval 'db.adminCommand({getParameter: 1, featureCompatibilityVersion: 1})'</code> (if you're using the same credentials as the guide).</li>
</ol>
<h3>Restarting everything</h3>
During my development process, I had multiple occasions where I had to restart everything. Here's my way of doing that:
<ol>
<li>Delete the config's resources: <code>kubectl delete -f config/samples/arbitrary_statefulset_configuration/mongodb.com_v1_hostpath.yaml -n mongodb </code>.</li>
<li>Whilst (1) is pending, execute the following lines of code to make (1) being able to finish:</li>
</ol>
<pre><code>kubectl patch pv data-volume-0 -p &quot;{\&quot;metadata\&quot;:{\&quot;finalizers\&quot;:null}}&quot; -n mongodb
kubectl patch pv data-volume-1 -p &quot;{\&quot;metadata\&quot;:{\&quot;finalizers\&quot;:null}}&quot; -n mongodb
kubectl patch pv data-volume-2 -p &quot;{\&quot;metadata\&quot;:{\&quot;finalizers\&quot;:null}}&quot; -n mongodb
kubectl patch pv logs-volume-0 -p &quot;{\&quot;metadata\&quot;:{\&quot;finalizers\&quot;:null}}&quot; -n mongodb
kubectl patch pv logs-volume-1 -p &quot;{\&quot;metadata\&quot;:{\&quot;finalizers\&quot;:null}}&quot; -n mongodb
kubectl patch pv logs-volume-2 -p &quot;{\&quot;metadata\&quot;:{\&quot;finalizers\&quot;:null}}&quot; -n mongodb
</code></pre>
<ol start="3">
<li>Run the following lines of code:</li>
</ol>
<pre><code>kubectl delete deployments.apps mongodb-kubernetes-operator -n mongodb
kubectl delete crd mongodbcommunity.mongodbcommunity.mongodb.com
kubectl apply -f config/crd/bases/mongodbcommunity.mongodb.com_mongodbcommunity.yaml
kubectl apply -k config/rbac/ -n mongodb
kubectl create -f config/manager/manager.yaml -n mongodb
kubectl apply -f new-user.yaml -n mongodb
kubectl apply -f config/samples/arbitrary_statefulset_configuration/mongodb.com_v1_hostpath.yaml -n mongodb
</code></pre>
