-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathw2_2_MongoDB
80 lines (69 loc) · 2.47 KB
/
w2_2_MongoDB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
MongoDB
-----------
* Databases
----------
-> Databases are used to store structured information;
-> Databases support various operations on the data
i. query
ii. insert
iii. update
iv. delete;
-> SQL(Structured Query Language) based on relational databases, have been very popular means of storing data;
-> NoSQL databases are increasingly becoming popular to address sql database challenges;
NoSQL Databases
--------------
4 different broad categories
---------------------------
a. Document databases (MongoDB); JSON document; -> document -> collection -> database
b. Key-value databases; (Redis)
c. Column-family databases (Cassandra)
d. Graph databases (Neo4J)
Why NoSQL?
-----------
a. Scalability (the capacity to be changed in size or scale, o be used or produced in a range of capabilities)
i. Availability
ii. Consistency
iii. Partition tolerance
b. Ease of Deployment
- No object-relation mapping required; (map the relatinal data into objects that can be used in the code);
MongoDB
----------
-> Documentbased Database;
-> Mongo Server can support multiple databases simultaneously;
-> Database consists of a set of collections;
-> A collection is a set of document;
-> Document - JSON document;
MongoDB Format
----------------
-> When Mongo stores the data on the disk, it stores it in a BSON (Binary JSON format);
- Supports the length prefix on each value; easy to skip over a field;
- Information about the type of a field value;
- Additional primitives types not supported by raw JSON like UTC date time, raw binary, and OjectId are allowed in BSON;
MongoDB ObjectId
-------------------
-> Every document in Mongo must have an "_id" field that is unique, could be created by default;
-> ObjectId is a 12 byte field: |Timestamp (4) | Machine ID (3) | Proc. ID(2) | Increment (3) |
id.getTimestamp() -> returns the timestamp in ISO Date format;
https://www.mongodb.com/
mongod --dbpath=data
mongo
----------------------
32-bit system;
download mongodb compatible with 32-bit operating system;
-> create a data/db folder as well as mongodb folder;
(within the MongoDB\Server\3.2\bin)
-> cmd -> mongod --storageEngine=mmapv1 --dbpath=C:\data\db
-> cmd -> mongo.exe
within the installed folder
cmd1: mongod --storageEngine=mmapv1 --dbpath=C:\data\db
cmd2: mongo.exe
Instructions
----------------
i. db
ii. use conFusion
iii.db
iv. db.help()
v. db.dishes.insert({ name: "Uthapizza", description: "Test" });
vi. db.dishes.find().pretty();
vii.var id = new ObjectId();
id.getTimestamp();