Question

In: Computer Science

Using MongoDB, what command would you enter to retrieve this document using only the zip code...

Using MongoDB, what command would you enter to retrieve this document using only the zip code 11242?

db.inspections.find(???????)


Database: city
Collection: inspections

{"_id":{"$oid":"56d61033a378eccde8a898ae"},
"id":"23536-2015-ENFO",
"certificate_number":5373970,
"business_name":"NZO CORP.",
"date":"Apr 22 2015",
"result":"Violation Issued",
"sector":"Grocery-Retail - 808",
"address":{"city":"BROOKLYN",
     "zip":11242,
     "street":"COURT ST",
     "number":26}}

Solutions

Expert Solution

Code:

db.inspections.find({ "address.zip": 11242})

This is a simple code. Now let us break down the query into simpler part.


Explanation of the Query:

1) How we write a find command ?

  • db.collection.find()

2) The document in which you are using this function is know as embedded document. This approach always maintains the data which is related in a single document hence it is easy to retrieve and maintain the document. This approach is used in many-to-one relationship.

3) Hence to access the specific field in an embedded document we have to use a dot notation. We have to concatenate i.e. join the embedded document with a dot and the name of the field within the quotes.

4) So as we wanted zip which was inside embedded document i.e. address so we wrote address.zip. Here we used concatenation using the dot.

5) Now this was the selection of the variable which had to find. We have to find zip value 11242 so as the value is in integer we will not put quotes and the query will look like "address.zip": 11242.

Screenshot:

Database example:

Query:

Output:

Note: If you have any more query please comment. I will be ready to help you. Thanks.


Related Solutions

In MongoDB using Linux how do you Execute the command to find the size of a...
In MongoDB using Linux how do you Execute the command to find the size of a single document of your choosing from the enron database Execute the command to find the size of the collection of documents in the enron database
Since you will be using zip or compressed files; Explain how to zip (compress) and unzip...
Since you will be using zip or compressed files; Explain how to zip (compress) and unzip (uncompress/extract) files. How to extract or uncompress files into a folder. Why do you need to uncompress/extract the files? The importance of knowing about zip/compressed files in digital forensics.
Consider an employee using their computer to send and retrieve email at their workplace. Only Ethernet...
Consider an employee using their computer to send and retrieve email at their workplace. Only Ethernet networks are used for physical connectivity, but the mail server is located on a separate network. The employee’s network and the mail server’s network are connected by a single router which also has a connection to the Internet via the workplace’s ISP. Explain how the employees email client sends and receives emails using the email server, indicating any protocols involved and where any encapsulation/decapsulation...
Let X = the number of nonzero digits in a randomly selected zip code. What are...
Let X = the number of nonzero digits in a randomly selected zip code. What are the possible values of X? Is X discrete or continuous? Give three possible outcomes and their associated X values. A college professor always finishes his lectures within 2 minutes after the bell rings to end the period and the end of the lecture. Let X = the time that elapses between the bell and the end of the lecture. What could be the values...
Using Python code create a program only with beginners code. You are taking online reservations at...
Using Python code create a program only with beginners code. You are taking online reservations at the The inn Ask for your client’s name and save in a variable Ask how many nights your client will be staying and save in a variable Room rental is $145 per night Sales tax is 8.5% Habitation tax is $5 per night (not subject to sales tax) Print out: Client’s name Room rate per night Number of nights Room cost (room rate *...
In R/ R Studio, what code would I enter to find the answers to these questions?...
In R/ R Studio, what code would I enter to find the answers to these questions? What is the code to find the descriptive/ summary statistics of all variables in a data set and how do i find the mean values? What is the code to measure the skewness measure of delta time for all of all the values in the data set? What is the code to draw a histogram and q-q plot of the natural log of a...
Troubleshooting Exchange Server 2013 Type Test-ServiceHealth and press <Enter> What does this command do? When would...
Troubleshooting Exchange Server 2013 Type Test-ServiceHealth and press <Enter> What does this command do? When would you use it? Why is it helpful? Type Test-MapiConnectivity and press <Enter> What does this show? Type Test-MapiConnectivity Mjackson and press <Enter> What does this show? What is the difference between the commands in step 2 and 3? Type Get-MailboxStatistics Mjackson | Format-List DisplayName, IsQuarantined What does this command tell us? When would you run this command?        5 . What is a concern...
At the command prompt, type cd etc and press Enter. What error message did you receive...
At the command prompt, type cd etc and press Enter. What error message did you receive and why?
What would you document if you had a telephone conversation with a patient?
What would you document if you had a telephone conversation with a patient?
If you have an application that only needs to retrieve items from a very large dictionary,...
If you have an application that only needs to retrieve items from a very large dictionary, and it never needs to insert or delete new items, which implementation would be the most efficient? Justify your assertion.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT