sample questions

 

1.

  • Create a new database in MongoDB using the use command. Insert a document with your name, email address, and phone number into a new collection called contacts.
  • Query the contacts collection and retrieve all documents using the find method.
  • Query the contacts collection and retrieve only the name field of all documents using the find method and projection.
  • Insert two new documents into the contacts collection. One should have the name "John Smith" and the other should have the name "Jane Doe".

2.

 

  • Create a new database in MongoDB using the use command. Insert a document with your name, email address, and phone number into a new collection called contacts.
  • Insert two new documents into the contacts collection. One should have the name "John Smith" and the other should have the name "Jane Doe".
  • Update the document for "John Smith" to include an additional field called address with the value "123 Main St".
  • Update the document for "John Doe" to include an additional field called address with the value "125 Second St".

 

3.  insert 5 documents in contacts collection

 

{

  "name": "John Smith",

  "email": "john.smith@example.com",

  "phone": "+1 (555) 123-4567",

  "address": {

    "street": "123 Main St",

    "city": "Anytown",

    "state": "CA",

    "zip": "12345",

    "country": "USA"

  }

},

{

  "name": "Jane Doe",

  "email": "jane.doe@example.com",

  "phone": "+1 (555) 987-6543",

  "address": {

    "street": "456 Oak St",

    "city": "Sometown",

    "state": "NY",

    "zip": "54321",

    "country": "USA"

  }

},

{

  "name": "Bob Johnson",

  "email": "bob.johnson@example.com",

  "phone": "+1 (555) 555-5555",

  "address": {

    "street": "789 Elm St",

    "city": "Anyville",

    "state": "TX",

    "zip": "67890",

    "country": "USA"

  }

},

{

  "name": "Emma Williams",

  "email": "emma.williams@example.com",

  "phone": "+44 123 456 7890",

  "address": {

    "street": "10 Downing St",

    "city": "London",

    "state": "",

    "zip": "SW1A 2AA",

    "country": "UK"

  }

},

{

  "name": "Hiroshi Nakamura",

  "email": "hiroshi.nakamura@example.com",

  "phone": "+81 3-1234-5678",

  "address": {

    "street": "2-1-2 Otemachi",

    "city": "Chiyoda-ku",

    "state": "Tokyo",

    "zip": "100-0004",

    "country": "Japan"

  }

}

  • Query the contacts collection and retrieve all documents sorted by name in ascending order.
  • Query the contacts collection and retrieve all documents sorted by name in descending order.

 

4. Set 1

1.    Create a new database called blog and a collection called posts.

2.    Insert a new document into the posts collection with the fields title, content, author, and created_at.

3.    Query the posts collection and retrieve all documents.

4.    Query the posts collection and retrieve only the title and created_at fields of all documents.

5.    Update the document for a specific post by its title field to change its content.

Set 2

1.    Create a new database called ecommerce and a collection called products.

2.    Insert 5 new documents into the products collection, each with the fields name, description, price, quantity, and created_at.

3.    Query the products collection and retrieve all documents.

4.    Query the products collection and retrieve only the name and price fields of all documents.

5.    Update the document for a specific product by its name field to change its quantity.

Set 3

1.    Create a new database called music and a collection called artists.

2.    Insert 3 new documents into the artists collection, each with the fields name, genre, albums, and members.

3.    Query the artists collection and retrieve all documents.

4.    Query the artists collection and retrieve only the name and genre fields of all documents.

5.    Update the document for a specific artist by its name field to change its genre.

Set 4

1.    Create a new database called recipes and a collection called dishes.

2.    Insert 2 new documents into the dishes collection, each with the fields name, description, ingredients, and instructions.

3.    Query the dishes collection and retrieve all documents.

4.    Query the dishes collection and retrieve only the name and description fields of all documents.

5.    Update the document for a specific dish by its name field to change its description.

Set 5

1.    Create a new database called movies and a collection called actors.

2.    Insert 4 new documents into the actors collection, each with the fields name, birthdate, nationality, and movies.

3.    Query the actors collection and retrieve all documents.

4.    Query the actors collection and retrieve only the name and nationality fields of all documents.

5.    Update the document for a specific actor by its name field to change its birthdate.

Set 6

1.    Create a new database called store and a collection called customers.

2.    Insert 3 new documents into the customers collection, each with the fields name, email, phone, and address.

3.    Query the customers collection and retrieve all documents.

4.    Query the customers collection and retrieve only the name and email fields of all documents.

5.    Update the document for a specific customer by its email field to change its phone.

 

 

1.    Create an index on the name field of a collection called students.

2.    Query the students collection and retrieve all documents sorted by the name field in ascending order.

3.    Query the students collection and retrieve only the documents where the name field contains the word "John".

4.    Create a compound index on the name and age fields of the students collection.

5.    Query the students collection and retrieve only the documents where the name field contains the word "John" and the age field is greater than or equal to 18.

Set 2

1.    Create an index on the title field of a collection called books.

2.    Query the books collection and retrieve all documents sorted by the title field in descending order.

3.    Query the books collection and retrieve only the documents where the title field contains the word "MongoDB".

4.    Create a text index on the description field of the books collection.

5.    Query the books collection and retrieve only the documents where the description field contains the phrase "NoSQL database".

Set 3

1.    Create an index on the name field of a collection called employees.

2.    Query the employees collection and retrieve all documents sorted by the name field in ascending order.

3.    Query the employees collection and retrieve only the documents where the name field contains the word "Smith".

4.    Create a hashed index on the id field of the employees collection.

5.    Query the employees collection and retrieve only the documents where the id field equals a specific value.

Set 4

1.    Create an index on the date field of a collection called orders.

2.    Query the orders collection and retrieve all documents sorted by the date field in descending order.

3.    Query the orders collection and retrieve only the documents where the date field is between two specific dates.

4.    Create a compound index on the customer_id and product_id fields of the orders collection.

5.    Query the orders collection and retrieve only the documents where the customer_id field equals a specific value and the product_id field is not null.

 

 

Set 1

1.    Use the $match stage to retrieve only the documents where the age field is greater than or equal to 18.

2.    Use the $group stage to group the documents by the gender field and calculate the average age for each group.

3.    Use the $project stage to only retrieve the name and age fields of the documents.

4.    Use the $sort stage to sort the documents by the age field in descending order.

5.    Use the $limit stage to retrieve only the top 5 documents.

Set 2

1.    Use the $match stage to retrieve only the documents where the status field equals "active".

2.    Use the $group stage to group the documents by the category field and count the number of documents in each group.

3.    Use the $project stage to only retrieve the category and price fields of the documents.

4.    Use the $sort stage to sort the documents by the price field in ascending order.

5.    Use the $limit stage to retrieve only the top 10 documents.

Set 3

1.    Use the $match stage to retrieve only the documents where the type field equals "book".

2.    Use the $group stage to group the documents by the author field and calculate the total price for each group.

3.    Use the $project stage to only retrieve the author and price fields of the documents.

4.    Use the $sort stage to sort the documents by the price field in descending order.

5.    Use the $limit stage to retrieve only the top 3 documents.

Set 4

1.    Use the $match stage to retrieve only the documents where the date field is between two specific dates.

2.    Use the $group stage to group the documents by the product field and calculate the total quantity for each group.

3.    Use the $project stage to only retrieve the product and quantity fields of the documents.

4.    Use the $sort stage to sort the documents by the quantity field in descending order.

5.    Use the $limit stage to retrieve only the top 5 documents.

 

1.       Write a Python program in Jupyter to create following documents in MongoDB

 

DB: Fruits

Collection: New

Documents:

                { name: banana, color:yellow, no:5, price:10}

                { name: grape, color:dark blue, no:100, price:2}

 

DB: Countries

Collection: New1

Documents:

                { name: India, capital:delhi, no_states:28 }

                { name: USA, capital:Washington DC, no_states:50}

 

2.       Write a Python program in Jupyter to create following documents in MongoDB

 

DB: Sports

Collection: New1

Documents:

                { name: cricket, level:international, no:11, players:{batsmen:[ram,lokesh,veeru,bodhan,rajesh],bowlers:[venkat,kapil,gowtham],Allrounders:[jaiswal,raju] WK:[kethan]}}

 

                { name: hockey, level:national, no:10, players:{GK:1,Offense:4,defense:5}

 

1.       Write a Python program in Jupyter to create following documents in MongoDB

 

DB: Sports

Collection: New

Documents:

                { name: cricket, level:international, no:11}

                { name: hockey, level:national, no:10}

 

DB: Countries

Collection: New1

Documents:

                { name: India, capital:delhi, no_states:28 }

                { name: USA, capital:Washington DC, no_states:50}

 

2.       Write a Python program in Jupyter to create following documents in MongoDB

 

DB: Sports

Collection: New1

Documents:

                { name: cricket, level:international, no:11, players:{batsmen:[ram,lokesh,veeru,bodhan,rajesh],bowlers:[venkat,kapil,gowtham],Allrounders:[jaiswal,raju] WK:[kethan]}}

 

                { name: hockey, level:national, no:10, players:{GK:1,Offense:4,defense:5}

 

1.       Write a Python program in Jupyter to create following documents in MongoDB

 

DB: Sports

Collection: New

Documents:

                { name: cricket, level:international, no:11}

                { name: hockey, level:national, no:10}

 

DB: students

Collection: col1

Documents:

                { name: sudheer, degree:BTech, sem:6, subjects:[s1,s2,s3] }

                { name: Rakesh, degree:BTech, sem:5, subjects:[s1,s2] }

 

2.       Write a Python program in Jupyter to create following documents in MongoDB

 

DB: Sports

Collection: New

Documents:

                { name: cricket, level:international, no:11, players:{batsmen:5,bowlers:3,Allrounders:2, WK:1}

 

                { name: hockey, level:national, no:10, players:{GK:1,Offense:4,defense:5}

 

Comments

Popular posts from this blog

AIDS Meanstack Sample questions

Express.js Registration form data 2 Server