Challenge 11: Mongo Basics
For this challenge you will run through a set of CRUD operation with Mongo.
To get started, you will need to create a noteful
database with a notes
collection and populate it with documents.
mongoimport
. Note, the data in ths gist is formatted as a proper JSON array of objects, so the import process is slightly different that the Restaurants data used earlier. Below is the mongoimport
command with --jsonArray
flag.mongoimport -d noteful -c notes --drop --jsonArray --file ~/<path-to-unzipped-data-file>
Next, create a mongo-queries.js
file. In the file, create the queries to solve each of the following:
Write a MongoDB query to display all the documents in the collection notes.
Write a MongoDB query to display all the documents in the collection notes and format the results to be 'pretty'.
Write a MongoDB query to display the fields title and content for all the documents in the collection notes.
Write a MongoDB query to display the fields title and content but exclude the field _id for all the documents in the collection notes.
Write a MongoDB query to display only the title field for all the documents in the collection notes and sort the results by _id in descending order.
Write a MongoDB query to display all the documents from the collection notes which contain the title '5 life lessons learned from cats'.
Write a MongoDB query to display the first 5 documents from the collection notes.
Write a MongoDB query to display the next 5 documents from the collection notes after skipping the first 5.
Write a MongoDB query to display the total number of documents in the collection notes.
Write a MongoDB query to display the documents from the collection notes which have an _id that is greater than "000000000000000000000007".
Write a MongoDB query to display the documents from the collection notes which have an _id which is greater than or equal to "000000000000000000000009" but less than or equal to "000000000000000000000017".
Write a MongoDB query to display the documents from the collection notes which have an _id which is less than or equal to "000000000000000000000007".
Write a MongoDB query to display only one document from the collection notes.
Write a MongoDB query to display only the title of one document from the collection notes (_id can be included).
Write a MongoDB query to display only the title of one document from the collection notes (_id excluded).
Write a MongoDB query to insert one document into the collection notes. The title and content fields can be whatever you like.
Write a MongoDB query to insert two note documents into the collection notes. The title and content fields can be whatever you like.
Write a MongoDB query to modify the title and content fields of the document from the collection notes with _id "000000000000000000000003". Change the title and content to be whatever you like.
Write a MongoDB query to modify only the title field of the document from the collection notes with _id "000000000000000000000007". The content field should remain unchanged.
Write a MongoDB query to modify the title and content fields of all the documents in the collection notes that have an _id field greater than "000000000000000000000014".
Write a MongoDB query to remove only the title field from the document in the collection notes with _id "000000000000000000000008".
Write a MongoDB query to remove the content fields from all documents in the collection notes with _id less than or equal to "000000000000000000000006".
Write a MongoDB query to remove the title fields from all documents in the collection notes with _id less than or equal to "000000000000000000000003".
Write a MongoDB query to remove the document from the collection notes that has an _id "000000000000000000000017".
Write a MongoDB query to remove the documents from the collection notes that have an _id which is not less than "000000000000000000000018".
Write a MongoDB query to remove the documents from the collection notes that have an _id which is greater than or equal to "000000000000000000000013" and contain the string 'dogs' in the title.
Write a MongoDB query to display all the documents from the collection notes which do not have a title field.
Write a MongoDB query to remove all the documents from the collection notes which contain the string 'cat' in the title but not the string 'the'.
Write a MongoDB query to display all the documents from the collection notes that have a title field which does not contain the string 'dogs' and does contain a title field.