paololatoja
5/4/2018 - 2:19 PM

MongoDB Quiz + Notes

MongoDB Quiz + Notes

Objective: 1) How many tweets are in the tweets collection (You can use the count operator)
			Answer: db.tweets.find().count() 
     			Answer = 966  

	   2) Find all the tweets that are in 'en', and how many are them?
		db.tweets.find({"lang": {$eq: "en"}}).count() 
    		Answer = 702

	   3) Find all tweets that has a hashtag of "QPRWHU"
			db.tweets.find({"entities.hashtags.text": {$eq:"QPRWHU"}}).count()
			Answer = 1
		
	   4) Find all the tweets that has a hashtag of "QPRWHU", and has a tweet count of greater than 120
	db.tweets.find({
		$and: [
			{"entities.hashtags.text": {"$eq":"QPRWHU"}},
			{"retweet_count": {"$gt": 120}}
		     ]
		})
			
	   5) How many users are there that has a followers_count greater than 8279353
	   db.tweets.count({
		"user.followers_count": { $gt:8279353 }
		});

		Answer = 137
		


db.tweets.find({"entities.hashtags.text": {$eq:"QPRWHU"}}).


db.tweets.find({
	$and: [{
		"entities.hashtags.text": {$eq: "QPRWHU"}
       		},

       		{
			"statuses_count" : {$gt:120}
       		}

		]
})



transfer collection "tweets" from database:test to database:twitter

db.tweets.count


==========================================================
db.tweets.find({


{$gt: ""}



}).count()

***********************===============================*****************===================================================
--------- NOTES ----------

Install MongoDB
Setup MongoDB shell and server (Also set environment variables to use in \bin folder)

Collection = A database full of documents
	documents = class
	data = students


mongod --dpath or --dbpath "filePath"  (Sets where the mongodb will be installed)

(command) mongo = shell for running mongodb commands
(command) mongod or mongod --dpath "filePath" = opens server 
	(Keep this open while using mongodb, then start another terminal for 'mongo' command)

Learning Sources: 

udemy.com/mongodb-essentials/
udemy.com/user/patrick251   (Great and Free Udemy Courses)
slides.com/kyeljohndavid
https://docs.mongodb.com/
https://www.tutorialspoint.com/mongodb/index.htm


====================================================================================================

Database > Collections (possible multiple) > Documents (pm) > Data (pm)

-show dbs
-use DatabaseName (if this database name is non-existent, it will create it then use it)
-db (checks currently using database)

navigate to proper current working directory first, then . . .


mongod --directoryperdb --dbpath C:\Folder\Path\Directory\data\db --logpath C:\database\logs\directory\mongo.log --logappend --install 


--directoryperdb  (uses a separate directory/folder to store data for each database
		The directories are under the '--dbpath' directory

--logappend --install (runs as a service)


mongo => shell that initializes to run mongo query/queries and update data

mongod => server

net start MongoDB  (starts the MongoDB server as a service)

C:\mongoDB\Server\3.6\log

C:\mongoDB\Server\3.6\data\db

mongod --directoryperdb --dbpath C:\mongoDB\Server\3.6\data\db --logpath C:\mongoDB\Server\3.6\log\mongo.log --logappend --install