MongoDB can be used as a file system, taking advantage of load balancing and data replication features over multiple machines for storing files.
In this article we will learn how to update document in mongo dB
with a practical example
previous articles have provided an introduction to mongo dB and the set up and installation,
and few command line options.You can get them from the following:
The objective of the article is to learn about updating document in
update command is atomic within a document. No two clients may update the same document
at the same time, two update commands issued concurrently will be executed one
after another. Here is the syntax of the update command...
have to specify which collection we gonna update
will need to specify which document we are targeting
will need to specify what change we want to see in active i.e. update parameter
may specify other options such as do we want to change only one the first document
found matching the query or do we want to upsert(do we want to save a new
record in case the query doesn’t match any document will generate the document on the
them in a practical example
save a record with the id 1 and a value x of 10...
use the increment operator which takes the field name and the amount of which
we want to implement.
check the value
second scenario one client wants to add the field to the document while another
client is trying to implement. So we already have our self a record in there
with only one field x=10.
along the client that wants to add the field…we can issue a update command...and
again the same client want to increment the value of x we can specify only the
x to be incremented as shown below
ok right now we have the fields x and y now if we wanna remove the field y we can issue the unset command the unset command takes the field name and a arbitary value.
In this article we have learn about updating documents in mongo database.