Use update method with the multi flag set to true

db.users.update(
  { "welcomeAck": { "$exists": false } },
  { "$set": { "welcomeAck": true } },
  { "multi": true }
);

Or the equivalent shortcut with updateMany:

db.users.updateMany(
  { "welcomeAck": { "$exists": false } },
  { "$set": { "welcomeAck": true } }
);

Reference - https://docs.mongodb.com/manual/tutorial/update-documents/


Shared with from Codever. 👉 Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

Codever is open source on Github ⭐🙏

To list services, pods and deployments resources from kubernetes namespace use the kubectl get command with --namespace=my-namespace (short -n)

# Set the "current" namespace for context
kubectl config set-context --current --namespace=my-namespace

# Get commands with basic output
kubectl get services                          # List all services in the namespace
kubectl get pods --all-namespaces             # List all pods in all namespaces
kubectl get pods -o wide                      # List all pods in the current namespace, with more details
kubectl get deployment my-dep                 # List a particular deployment
kubectl get pods                              # List all pods in the namespace
kubectl get pods  -n my-namespace             # List all pods in the "my-namespace" namespace (in namespace not set)
kubectl get pod my-pod -o yaml                # Get a pod's YAML

Reference - https://kubernetes.io/docs/reference/kubectl/cheatsheet/


Shared with from Codever. 👉 Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

Codever is open source on Github ⭐🙏

First use the @JsonFilter jackson annotation where you define an id of the filter

import com.fasterxml.jackson.annotation.JsonFilter;
import com.fasterxml.jackson.annotation.JsonProperty;

@JsonFilter("IndividualComparisonResultsFilter")
public class ComparisonResultBulk implements Serializable {

  //other fields ignored for brevity

  @JsonProperty("max_latency_millis")
  private String maxLatencyMillis;

  @JsonProperty("individual_comparison_results")
  private List<ComparisonResult> comparisonResults;

  @JsonProperty("not_comparable_results_size")
  private Integer notComparableResultsSize;

  @JsonProperty("not_comparable_results")
  private List<ComparisonResult> notComparableResults;
}

Then create a filterProvider, for example a SimpleFilterProvider for the id where you set the filter options.

In the example below everything is serialized except two properties with the help of SimpleBeanPropertyFilter.serializeAllExcept() method (serializeAll() is also present, and the opposite SimpleBeanPropertyFilter.filterOutAllExcept("individual_comparison_results", "not_comparable_results") which would serialize only these properties). In the end set the filterProvider set to the ObjectMapper where you serialize your object:

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;

private ComparisonReport generateReport(ComparisonResultBulk comparisonResultBulk)
      throws JsonProcessingException {
    ComparisonReport comparisonReport = new ComparisonReport();

    ObjectMapper mapper = new ObjectMapper();
    SimpleFilterProvider filterProvider = new SimpleFilterProvider();
    filterProvider.addFilter("IndividualComparisonResultsFilter", SimpleBeanPropertyFilter.serializeAllExcept("individual_comparison_results", "not_comparable_results"));
    mapper.setFilterProvider(filterProvider);

    comparisonReport.setPayload(mapper.writeValueAsBytes(comparisonResultBulk));

    return comparisonReport;
}

Shared with from Codever. 👉 Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

Codever is open source on Github ⭐🙏

Use case

Some code snippets I save are really long or maybe too wide, due to comments of course, to read them easily in the code text area. In this case it is very practical to view them in full screen, a feature I implemented over the passing weekend:

Toggle fullscreen for snippets
Toggle fullscreen for snippets

For the implementation I used screenfull.js1, which is a simple wrapper for cross-browser usage of the JavaScript Fullscreen API2.

Let’s see how this goes exactly.

Continue Reading ...

Use the @Enumerated(EnumType.STRING) annotation:

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;

@Entity
public class ComparisonReport implements Serializable {

  public static final String TABLE_NAME = "T_COMPARISON_REPORT";
  public static final String COLUMN_TRIGGER_TYPE = "TRIGGER_TYPE";

  @Column(name = COLUMN_TRIGGER_TYPE)
  @Enumerated(EnumType.STRING)
  private ReportTriggerType triggerType;

 //others ignored for brevity
}

The enum itself looks something the following

public enum ReportTriggerType {
    MANUAL("MANUAL"),
    AUTOMATIC("AUTOMATIC");

    private String value;

    ReportTriggerType(String source) {
      this.value = source;
    }

    public String getValue() {
      return value;
    }
  }

Shared with from Codever. 👉 Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

Codever is open source on Github ⭐🙏