top of page

MongoDB Studio 3T Practice Set Using Tweets.json Dataset | Realcode4you

Install MongoDB and Studio 3T on your computer, create a new database with a name and import 'Tweets.json' (available on iLearn) as a collection. Then complete the following exercises.



Exercise

1. Insert 2 new Tweets to the collection.

2. Write a MongoDB query that returns all the Tweets.

3. Write a MongoDB query to find one of your Tweets with user’s name: "user 30".

4. Update two Tweets to have two tags called “My first tag” and “My second tag” respectively. Show two ways to do this. Do the first one using update() and do the second one using save(). Hint: for save(), you might want to query the object, store it in a variable first; then update it and save the update.

5. Write a MongoDB query to retrieve all documents from the Tweets collection where user name equals either "user 30" or "user 40".

6. Write a MongoDB query to retrieve all documents from the Tweets collection where user screen_name is "Twitter User" and user location is "Internet". (Specify AND Conditions)

7. Write a MongoDB query to retrieve all documents from the Tweets collection where user screen_name is "Twitter User" or user url is "user URL". (Specify OR Conditions)

8. Write a MongoDB query to retrieve all documents from the Tweets collection where user id is not 224499494502


Solution

1. Insert 2 new Tweets to the collection.

A 1.

Solution 1:

//Tweet 1
db.tweets.insert(
{
"created_at": "Thu Apr 06 15:24:15 +0000 2020",
"id_str": "1850006245121695744",
"text": "Have a nice day",
"user": {
"id": NumberLong(2244456599494501),
"name": "user 01",
"screen_name": "Twitter User",
"location": "Internet",
"url": "user URL",
"description": "user description"
},
"place": {
},
"entities": {
        "hashtags": [
        ],
        "urls": [{
                "url": "twt url sample",
                "unwound": {
                        "url": "url sample",
                        "title": "web page title"
                }
        }],
        "user_mentions": [
        ]
  }
})

//Tweet 2
db.tweets.insert(
{
        "created_at": "Thu Apr 06 15:24:15 +0000 2020",
        "id_str": "1850006245121695744",
        "text": "Good Morning",
        "user": {
                "id": NumberLong(2244456599494501),
                "name": "user 01",
                "screen_name": "Twitter User",
                "location": "Internet",
                "url": "user URL",
                "description": "user description"
        },
        "place": {
        },
        "entities": {
                "hashtags": [
                ],
                "urls": [{
                        "url": "twt url sample",
                        "unwound": {
                                "url": "url sample",
                                "title": "web page title"
                        }
                }],
                "user_mentions": [
                ]
        }
})

Solution 2:

db.tweets.insert(
[{
                "created_at": "Thu Apr 06 15:24:15 +0000 2020",
                "id_str": "1850006245121695744",
                "text": "Hi",
                "user": {
                        "id": 2244456599494501,
                         "name": "user 01",
                         "screen_name": "Twitter User",
                         "location": "Internet",
                         "url": "user URL",
                         "description": "user description"
                 },
                "place": {
                },
                "entities": {
                           "hashtags": [
                            ],
                           "urls": [{
                                   "url": "twt url sample",
                                   "unwound": {
                                           "url": "url sample",
                                           "title": "web page title"
                                    }
                           }],
                           "user_mentions": [
                           ]
                }
},
{
                "created_at": "Thu Apr 06 15:24:17 +0000 2020",
                "id_str": "8510006245121695744",
                "text": "Welcome",
                "user": {
                       "id": 224499494503,
                       "name": "user 03",
                       "screen_name": "Twitter User",
                       "location": "Internet",
                       "url": "user URL",
                       "description": "user description"
                 },
                 "place": {
                 },
                 "entities": {
                           "hashtags": [
                            ],
                           "urls": [{
                                "url": "twt url sample",
                                "unwound": {
                                        "url": "url sample",
                                        "title": "web page title"
                                }
                           }],
                           "user_mentions": [
                           ]
                 }
            }
]
)

2. Write a MongoDB query that returns all the Tweets.

db.Tweets.find() 

3. Write a MongoDB query to find one of your Tweets with user’s name: "user 30".

db.Tweets.findOne({"user.name":"user 30"})

4. Update two Tweets to have two tags called “My first tag” and “My second tag” respectively. Show two ways to do this. Do the first one using update() and do the second one using save(). Hint: for save(), you might want to query the object, store it in a variable first; then update it and save the update.


Solution 1 (update ()):

db.Tweets.update({"user.name":"user 30"}, {$set:{"tag":"My first tag"}}) 
db.Tweets.update({"user.name":"user 40"}, {$set:{"tag":"My second tag"}}) 

Solution 2 (save ()):

var tweet_user30 = db.Tweets.findOne({"user.name":"user 30"})
tweet_user30["tag"] = "My first tag"
db.Tweets.save(tweet_user30)
var tweet_user40 = db.Tweets.findOne({"user.name":"user 40"})
tweet_user40["tag"] = "My second tag"
db.Tweets.save(tweet_user40)

5. Write a MongoDB query to retrieve all documents from the Tweets collection where user name equals either "user 30" or "user 40".

db.Tweets.find({"user.name":{ $in: [ "user 30", "user 40" ] } })

6. Write a MongoDB query to retrieve all documents from the Tweets collection where user screen_name is "Twitter User" and user location is "Internet". (Specify AND Conditions)

db.Tweets.find({$and: [{"user.screen_name": "Twitter User"}, {"user.location":"Internet"}]})

7. Write a MongoDB query to retrieve all documents from the Tweets collection where user screen_name is "Twitter User" or user url is "user URL". (Specify OR Conditions)

db.Tweets.find({ $or: [{"user.screen_name": "Twitter User"}, {"user.url":"user URL"}]})

8. Write a MongoDB query to retrieve all documents from the Tweets collection where user id is not 224499494502.


Solution 1:

db.Tweets.find({"user.id":{$ne:224499494502}})

Solution 2:

db.Tweets.find({"user.id":{$not:{$eq:224499494502}}})

265 Comments


jytgf432
19 minutes ago

Hôm nọ mình có lướt qua một vài trang mạng và thấy nhiều người bàn tán về liên hệ TX88 đặc biệt là về các thông tin thể thao trực tuyến. Thế là mình cũng tò mò ghé vào xem thử cách mà họ sắp xếp nội dung. Mình không đi sâu vào từng chi tiết mà chỉ dành chút thời gian để xem cách phân chia các mục và giao diện. Thực sự cảm thấy nếu các thông tin được trình bày rõ ràng, dễ hiểu thì việc đọc lướt cũng không gặp khó khăn gì. Với mình, chỉ cần nội dung gọn gàng như vậy là đủ để nắm bắt thông tin cơ bản.

Like

jytgf432
2 hours ago

Khi đọc các bài giới thiệu nền tảng giải trí, tôi thường thích những bài viết ngắn gọn để có thể xem nhanh trên điện thoại. Bài viết này có bố cục khá dễ theo dõi khi phần nhắc đến https://mm99.events/ được đặt ở giữa nội dung. Điều đó giúp mạch bài trở nên tự nhiên hơn và không tạo cảm giác quảng cáo quá sớm. Nội dung tập trung vào trải nghiệm chung của người dùng với giao diện dễ sử dụng và nhiều danh mục quen thuộc như slot, game bài hay mini game. Nhìn chung cách diễn đạt khá nhẹ nhàng và dễ hiểu.

Like

Janelle Moore
Janelle Moore
14 hours ago

Trong quá trình đọc các bài review nền tảng giải trí, tôi thường bị thu hút bởi những nội dung được viết ngắn gọn nhưng đầy đủ ý. Bài viết này đã làm khá tốt khi đưa bongdalu vào một cách tự nhiên, không gây cảm giác quảng cáo. Nhờ cách trình bày hợp lý, tôi có thể hiểu nhanh về các tính năng mà không cần đọc quá kỹ.

Like

Janelle Moore
Janelle Moore
14 hours ago

Khi đọc các bài viết giới thiệu nền tảng, mình thường đánh giá cao những nội dung được trình bày ngắn gọn nhưng vẫn đầy đủ thông tin. Ở bài này, phần nhắc đến go88 được đặt khá khéo léo ở giữa, giúp tổng thể nội dung trở nên tự nhiên hơn. Bài viết tập trung vào trải nghiệm người dùng với giao diện dễ nhìn, thao tác đơn giản và có thêm các danh mục quen thuộc như slot, game bài hay bóng đá để người đọc dễ hình dung.

Like

Janelle Moore
Janelle Moore
14 hours ago

Vì chủ yếu chơi trên điện thoại nên mình khá chú ý đến trải nghiệm mobile. Khi thử chuyển từ slot sang thể thao rồi qua game bài, mình thấy tốc độ tải khá nhanh. Nội dung được phân chia rõ nên việc điều hướng cũng nhẹ nhàng. Lúc mình vào iwin xem kỹ hơn thì thấy bắn cá và nổ hũ cũng được bố trí khá gọn. Theo mình, cách tổ chức này giúp iWIN mang lại trải nghiệm khá liền mạch.

Like

REALCODE4YOU

Realcode4you is the one of the best website where you can get all computer science and mathematics related help, we are offering python project help, java project help, Machine learning project help, and other programming language help i.e., C, C++, Data Structure, PHP, ReactJs, NodeJs, React Native and also providing all databases related help.

Hire Us to get Instant help from realcode4you expert with an affordable price.

USEFUL LINKS

Discount

ADDRESS

Noida, Sector 63, India 201301

Follows Us!

  • Facebook
  • Twitter
  • Instagram
  • LinkedIn

OUR CLIENTS BELONGS TO

  • india
  • australia
  • canada
  • hong-kong
  • ireland
  • jordan
  • malaysia
  • new-zealand
  • oman
  • qatar
  • saudi-arabia
  • singapore
  • south-africa
  • uae
  • uk
  • usa

© 2023 IT Services provided by Realcode4you.com

bottom of page