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 c开发者_JAVA技巧oncern, the way it could be done in java driver? Didn't find any docs about write concern in scripting for mongodb. Thx
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.
精彩评论