Update/remove

In document modifier operations, such as update and remove, we have a similar situation to the one we saw with find. If we have the shard key in the find section of the modifier, then mongos can direct the query to the relevant shard.

If we don't have the shard key in the find section, then it will again be a fanout operation.

The UpdateOne, replaceOne, and removeOne operations must have the shard key or the _id value.

The following table sums up the operations that we can use with sharding:

Type of operation

Query topology

Insert

Must have the shard key

Update

Can have the shard key

Query with shard key

Targeted operation

Query without shard key

Scatter-and-gather operation/fan out query

Indexed, sorted query with shard key

Targeted operation

Indexed, sorted query without shard key

Distributed sort merge

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset