Skip to content

Commit bc7c1d1

Browse files
committed
you're doing great
1 parent 1633829 commit bc7c1d1

File tree

3 files changed

+52
-83
lines changed

3 files changed

+52
-83
lines changed

046_mongodb/02_db/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ db.<collection name>.find()
5050
```
5151

5252
example
53+
```
54+
db.cats.insert({"firstname":"coco"})
55+
```
56+
5357
```
5458
db.cats.find().pretty()
5559
```

046_mongodb/04_document/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ db.crayonColors.insert([
6363
}
6464
])
6565
```
66-
[source](https://gist.githubusercontent.com/jjdelc/1868136/raw/c9160b1e60bd8c10c03dbd1a61b704a8e977c46b/crayola.json)
66+
[source of crayon json](https://gist.githubusercontent.com/jjdelc/1868136/raw/c9160b1e60bd8c10c03dbd1a61b704a8e977c46b/crayola.json)
6767

6868
```
6969
show collections

046_mongodb/README.md

Lines changed: 47 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -2,152 +2,117 @@
22

33
## 02_db
44

5-
### create
5+
#### create
6+
67
```
78
use <db name>
89
```
10+
The above will use the database of the provided name if it exists, and create it if it doesn't
11+
12+
#### use
913

10-
### use
1114
```
1215
use <db name>
1316
```
1417

15-
### see current db
18+
#### example
19+
```
20+
use temp
21+
```
22+
23+
The above will use the database of the provided name if it exists, and create it if it doesn't
24+
25+
#### see current db
26+
1627
```
1728
db
1829
```
1930

20-
### see all db
31+
#### see all db
32+
2133
```
2234
show dbs
2335
```
36+
You need to have at least one document in a db for it to be seen.
37+
38+
#### insert document
2439

25-
### insert document
2640
```
2741
db.<collection name>.insert({"name":"McLeod"})
2842
```
29-
If the collection doesn't exist, it is created
3043

31-
### view collections
44+
example
3245
```
33-
show collections
46+
db.dogs.insert({"name":"toby"})
3447
```
3548

36-
### view documents
49+
#### view documents
3750
```
3851
db.<collection name>.find()
3952
```
4053

41-
### drop db
54+
example
55+
```
56+
db.cats.insert({"firstname":"coco"})
57+
```
58+
59+
```
60+
db.cats.find().pretty()
61+
```
62+
63+
#### view collections
64+
```
65+
show collections
66+
```
67+
68+
#### drop db
4269
```
4370
db.dropDatabase()
4471
```
4572

4673
## 03_collection
4774

48-
### create implicitly
75+
# collection commands
76+
77+
#### create implicitly
4978
```
5079
db.<collection name>.insert({"name":"McLeod"})
5180
```
5281

53-
### create explicitly
82+
#### create explicitly
5483
```
55-
db.createCollection(<name>, <optional options>)
84+
db.createCollection(<name>, {<optional options>})
5685
```
5786

5887
#### optional options
5988
| option | type | description |
6089
| --- | --- | --- |
61-
| autoindex | bool | creates _id index automatically |
6290
| capped | bool | caps the size |
6391
| size | number | sets size of cap in bytes |
6492
| max | bool | maximum number of documents allowed in capped collection |
6593

94+
[other options including validation](https://docs.mongodb.com/manual/reference/method/db.createCollection/)
95+
6696
#### examples
6797
```
6898
db.createCollection("customers")
6999
```
70100

71101
```
72-
db.createCollection("customers",{autoindex:true})
73-
```
74-
75-
```
76-
db.createCollection("customers",{autoindex:true, capped:true,size:65536,max:1000000})
102+
db.createCollection("crs",{capped:true, size:65536,max:1000000})
77103
```
78104

79-
### view collections
105+
#### view collections
80106
```
81107
show collections
82108
```
83109

84-
### drop
110+
#### drop
85111
```
86112
db.<collection name>.drop()
87-
88113
```
89114

90115
## 04_document
91116

92-
### insert
93-
```
94-
db.<collection name>.insert({document})
95-
```
96-
97-
### insert multiple
98-
```
99-
db.<collection name>.insert(< [{document}, {document}, ..., {document}] >)
100-
```
101-
pass in an array of documents
102117

103118
## 05_query
104-
105-
### find
106-
```
107-
db.<collection name>.find()
108-
```
109-
110-
### find one
111-
```
112-
db.<collection name>.findOne()
113-
```
114-
115-
### pretty
116-
```
117-
db.<collection name>.find().pretty()
118-
```
119-
pretty prints the results
120-
121-
### operators
122-
123-
| operator | syntax | example |
124-
| --- | --- | --- |
125-
| equality | {key:value} | db.customers.find({"name":"McLeod"}).pretty() |
126-
| less than | {key:{$lt:value}} | db.customers.find({"age":{$lt:20}}).pretty() |
127-
| less than equals | {key:{$lte:value}} | db.customers.find({"age":{$lte:20}}).pretty() |
128-
| greater than | {key:{$gt:value}} | db.customers.find({"age":{$gt:20}}).pretty() |
129-
| greater than equals | {key:{$gte:value}} | db.customers.find({"age":{$gte:20}}).pretty() |
130-
| not equals | {key:{$ne:value}} | db.customers.find({"age":{$ne:20}}).pretty() |
131-
132-
### and
133-
```
134-
db.customers.find({$and: [{"name":"McLeod"}, {"age":20}]}).pretty()
135-
db.customers.find({$and: [{"name":"McLeod"}, {"age":{$lt:20}}]}).pretty()
136-
db.customers.find({$and: [{"name":"McLeod"}, {"age":{$gt:20}}]}).pretty()
137-
```
138-
139-
### or
140-
```
141-
db.customers.find({$or: [{"name":"McLeod"}, {"age":20}]}).pretty()
142-
db.customers.find({$or: [{"name":"McLeod"}, {"age":{$lt:20}}]}).pretty()
143-
db.customers.find({$or: [{"name":"McLeod"}, {"age":{$gt:20}}]}).pretty()
144-
```
145-
146-
### and or
147-
```
148-
db.customers.find({"role":"owner", $or: [{"name":"McLeod"}, {"age":20}]}).pretty()
149-
db.customers.find({"role":"owner", $or: [{"name":"McLeod"}, {"age":{$lt:20}}]}).pretty()
150-
db.customers.find({"role":"owner", $or: [{"name":"McLeod"}, {"age":{$gt:20}}]}).pretty()
151-
```
152-
WHERE role = 'owner' AND (name = 'mcleod' OR age = 20)
153-

0 commit comments

Comments
 (0)