Databases Reference
In-Depth Information
sort
Criteria by which to sort results.
update
A modifier document, the update to perform on the document found.
remove
Boolean specifying whether the document should be removed.
new
Boolean specifying whether the document returned should be the updated docu-
ment or the preupdate document. Defaults to the preupdate document.
Either "update" or "remove" must be included, but not both. If no matching document
is found, the command will return an error.
findAndModify has a few limitations. First, it can update or remove only one document
at a time. There is also no way to use it for an upsert; it can update only existing
documents.
The price of using findAndModify over a traditional update is speed: it is a bit slower.
That said, it is no slower than one might expect: it takes roughly the same amount of
time as a find , update , and getLastError command performed in serial.
The Fastest Write This Side of Mississippi
The three operations that this chapter focused on (inserts, removes, and updates) seem
instantaneous because none of them waits for a database response. They are not asyn-
chronous; they can be thought of as “fire-and-forget” functions: the client sends the
documents to the server and immediately continues. The client never receives an “OK,
got that” or a “not OK, could you send that again?” response.
The benefit to this is that the speed at which you can perform these operations is terrific.
You are often only limited by the speed at which your client can send them and the
speed of your network. This works well most of the time; however, sometimes some-
thing goes wrong: a server crashes, a rat chews through a network cable, or a data center
is in a flood zone. If the server disappears, the client will happily send some writes to
a server that isn't there, entirely unaware of its absence. For some applications, this is
acceptable. Losing a couple of seconds of log messages, user clicks, or analytics in a
hardware failure is not the end of the world. For others, this is not the behavior the
programmer wants (payment-processing systems spring to mind).
 
Search WWH ::




Custom Search