Deleting MongoDB documents – Part 10

Leave a comment

We’ve seen how to create and insert new documents, and you’ve seen how to update them, well let’s take a look at how to remove them. Now remember with update, it would only affect the first one, remove isn’t like that, if you pick a field that’s not unique, it will delete all the matching records. So let’s make sure it’s unique. So I’m going to go with title; brand: “Apple”.db.products.remove({brand: “Apple”})What if I’d like to identify a field that may have duplicates? Now right now we have

Learn More

Updating MongoDB documents – Part 9

Leave a comment

Fortunately it is pretty easy to update documents in MongoDB. We use db.products.update(), to update any document. Just now we inserted a product with name “laptop” and price 1200. Now I want to update price to 1000.db.products.update({name:’laptop’},{$set:{price:1000}})What if there’s more than one matching record? For example, if I base this on name, I can see I have two from smartphone. Will it change all of them? Well, let’s take a look. db.products.update, and again we’re going to tell it

Learn More

Constructing documents in MongoDB – Part 8

Leave a comment

The whole purpose of setting up a Mongo database is so that you can store documents, so a really, really critical operation is to create and insert those documents. Fortunately, that all occurs in one single step. One single command both creates the document and inserts it.Now the first thing we’d like to know is what are the current documents in this particular database? db.products.find() is the most basic find() command, and you’ll notice we have eleven products listed in this particular

Learn More

MongoDB data storage – Part 7

Leave a comment

Every MongoDB instance consists of three things Namespace file Journal file Data file. And it could consist of multiple data files, multiple journal files and multiple namespaces even. Now, we’re interested in understanding the database storage, so we would like to know more about these data files, more about what constitutes a MongoDB. Fortunately, there are some commands that will do that for us, let’s take a look at a few of those.First of all, I just want to know the size of the data files,

Learn More

Describing CRUD – Part 6

Leave a comment

There are four operations we need to talk about. All databases, whether they be traditional relational database systems, or NoSQL, they all require what are called CRUD operations. CRUD is an acronym that stands for Create, Read, Update and Delete. These operations are the fundamentals for all interactions within a database.MongoDB queries are very flexible in providing these operations. First of all, they give you the option of targeting a specific collection of documents, within the database.

Learn More