Cmdlets for MongoDB

Build 24.0.9060

UpdateScheme Parameter (Connect-MongoDB Cmdlet)

Sets replacing or merging target document with updating fields is performed by executing update statement.

Syntax

Connect-MongoDB -UpdateScheme string

Possible Values

Default, Merge

Data Type

cstr

Default Value

"Default"

Remarks

Sets replacing or merging target document with updating fields is performed by executing update statement. When the default value Default is used, the cmdlet updates the target document by replacing the whole original document with new one. When the value is set to Merge, only the specific field in the target document will be updated.

For example, if you have a collection 'classySample' as below.

{
  "_id": "1",
  "message": {
    "component_items": [{"locked": true}],
    "id":1
  }
}

UPDATE [classySample] SET [message.component_items.0.locked] = false  WHERE [message.id] = 1

In the query above, the 'message' document will be replaced with new document constructed with SET clause, the collection after updating looks like

{
  "_id": "1",
  "message": {
    "component_items": [
      {
        "locked": false
      }
    ]
  }
}

But when using Merge, only the 'locked' field in 'component_items' will be updated, the collection becomes

{
    "_id": "1",
    "message": {
        "component_items": [
            {
                "locked": false
            }
        ],
        "id": 1
    }
}

Copyright (c) 2024 CData Software, Inc. - All rights reserved.
Build 24.0.9060