Overview
KB
Technical FAQ
PHP Manual
CSS2 Manual
HTML Manual
JS Guide
JS Reference
PhpDock Manual
Nu-Coder Manual
PhpExpress Manual
PHP Joomla
Development
Learn PHP
 
<MongoDB\Driver\ServerApi::__constructMongoDB\Driver\WriteConcern::bsonSerialize>
^MongoDB\DriverLast updated: Mon, 26 Oct 2026

The MongoDB\Driver\WriteConcern class

(mongodb >=1.0.0)

Introduction

MongoDB\Driver\WriteConcern describes the level of acknowledgement requested from MongoDB for write operations to a standalone mongod or to replica sets or to sharded clusters. In sharded clusters, mongos instances will pass the write concern on to the shards.

Class synopsis

final class MongoDB\Driver\WriteConcern implements MongoDB\BSON\Serializable, Serializable {
/* Constants */
const string MAJORITY = "majority";
/* Properties */
public readonly string|int|null $w;
public readonly ?bool $j;
public readonly int $wtimeout;
/* Methods */
final public function bsonSerialize(): stdClass
final public function __construct(string|int $w, ?int $wtimeout = null, ?bool $journal = null)
final public function getJournal(): ?bool
final public function getW(): string|int|null
final public function getWtimeout(): int
final public function isDefault(): bool
}

Properties

w

The write concern value (integer number of nodes, the string "majority", or a custom write concern tag name), or null if not set.

j

Whether write operations must be committed to the journal before acknowledged, or null if not specified.

wtimeout

The timeout in milliseconds to wait for write concern acknowledgement. A value of 0 means to wait indefinitely.

Predefined Constants

MongoDB\Driver\WriteConcern::MAJORITY

Majority of all the members in the set; arbiters, non-voting members, passive members, hidden members and delayed members are all included in the definition of majority write concern.

Changelog

Version Description
PECL mongodb 2.3.0 Added public readonly properties.
PECL mongodb 1.7.0 Implements Serializable.
PECL mongodb 1.2.0 Implements MongoDB\BSON\Serializable.

Table of Contents


<MongoDB\Driver\ServerApi::__constructMongoDB\Driver\WriteConcern::bsonSerialize>
^MongoDB\DriverLast updated: Mon, 26 Oct 2026