user253202
user253202

Reputation:

Mongodb write concern in javascript update script

I need to write some update script for data via js, so is it possible to set for save or update operations write concern, the way it could be done in java driver? Didn't find any docs about write concern in scripting for mongodb. Thx

Upvotes: 1

Views: 1036

Answers (1)

Gates VP
Gates VP

Reputation: 45297

I believe you are looking for something like db.getLastError().

In Java/PHP/Python/etc, when you do WriteConcern.Safe or safe => true, you're actually doing a write command followed by a getLastError command. You can simulate that by using db.getLastError().

Please note that there are currently two MongoDB documents regarding shell scripting. The first is the Interactive Shell, which is the shell you're probably used to. In that shell, all commands are issued in "safe" mode by default. The other document regards scripting the shell, which has some specific issues (including that getLastError).

Definitely check out that second document to run script this way. Also note that basically all of the functionality available to the shell is available to the drivers. So if you have scripting skills in Python or you're comfortable writing Windows Services, these can also be used for managing the server.

Upvotes: 2

Related Questions