Which MongoDB command will show the available indexes for the "animals" collection? Review the Austin Animal Center data set for help constructing these queries. Select one. db.animals.getIndexes() db.animals.totalSize() db.animals.explain() db.animals.runCommand()
Added by Matthew F.
Close
Step 1
animals.getIndexes()` is used to retrieve the indexes for a collection. Show more…
Show all steps
Your feedback will help us improve your experience
Akash M and 93 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Using mongoimport, I imported the csv file "aac_shelter_outcomes.csv". After importing the csv file, how do I create a simple index on the key "breed"? Show an example query that will use this index and verify that the index will be used with the explain function. How do I create a compound index that will improve the performance of queries looking for breeds that have an "outcome_type" of "Transfer"? Show an example query that will use this compound index and confirm that the index will be used with the explain function.
Akash M.
Part 2: Writing Advanced MongoDB Queries We have a collection of populations by postal code named "codes" (see the codes.json file). The postal codes are in the _id field and are therefore unique. Documents look like this: { } Note that there are 50 non-overlapping states in the US with two-letter abbreviations such as NY and CA. In addition, the capital of Washington is within an area designated the District of Columbia and carries the abbreviation DC. For purposes of the mail, the postal service considers DC to be a "state." So in this dataset, there are 51 states. A city may overlap several postal codes. Write an aggregation query to answer the following questions. <descriptive text> in the result set is used as a placeholder for the correct answer. 6. Find the population of each state. The output should look like this: _id : "35045", city : "CLANTON", loc : [-86.64, 32.84], pop: 13990, state : "AL" { }, { <population of CA> <population of MT> _id : "CA", population : _id : "MT", population : },... 7. Find the population of the postal code in each state with the highest population. The output should look like this: { state : "WI", population : <highest population of a postal code in WI> }, { state : "WV", population : <highest population of a postal code in WV> }, ... 8. Find the population of each city in the state of New York (NY) and list the postal codes that are included in each city. The output should look like this: { }, { }, ... _id : "ELMIRA", population : <population of ELMIRA>, postal_codes : [ <PostalCode1 in ELMIRA>, <PostalCode2 in ELMIRA>, <PostalCode3 in ELMIRA> ], _id : "WHITESVILLE", population : <population of WHITESVILLE>, postal_codes : [ <PostalCode1 in WHITESVILLE> ], 9. Find the largest city in each state. The output should look like this: { }, { <population of the largest city in WI> <population of the largest city in VT> _id : "WI", city : <name of the largest city in WI>, population : _id : "VT", city : <name of the largest city in VT>, population : }, ... 10. Calculate the average population of cities in California (CA) and New York (NY) with populations over 30,000. The output should look like this: { pop : <average pop. of cities in CA and NY with population over 30000> }
Jerelyn N.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD