Home MongoDB
Post
Cancel

MongoDB

SQLOther Name
TablesCollections
rows/recodsDocuments

BSON(BinaryJSON)

JSON-like storage format

_id field: primary key If driver fails to provide a _id field with a unique ObjectId, the mongod service will add it automatically

example

1
2
3
4
5
6
7
{
  "_id": ObjectId("52d02240e4b01d67d71ad577"),
  "title": "First Blog Post",
  "comments": [
  ...
  ]
}

MongoDB replica set

The reason of Replication of databases

  1. protaction data to recover from hardware failure
  2. Increate read capacity

Start MongoDB

1
2
3
4
5
mongod
mongosh

use mean
show dbs

update()

1
2
3
4
5
6
7
8
9
mean > db.posts.update({"user":"alice"},{$set:{"title":"Fourth Post"}},{multi:true})
# output
{
  acknowledged: true,
  insertedId: null,
  matchedCount: 1,
  modifiedCount: 1,
  upsertedCount: 0
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
mean> db.posts.find()
[
  {
    _id: ObjectId("6512f266594890cfb846b144"),
    title: 'First Post',
    user: 'bob'
  },
  {
    _id: ObjectId("6512f301594890cfb846b145"),
    title: 'Second Post',
    user: 'pop'
  },
  {
    _id: ObjectId("6512f395594890cfb846b146"),
    title: 'Fourth Post',
    user: 'alice'
  }
]

save()

remove()

  • Can accept up to two arguments
  • first argument: the deletion criteria
  • second argument: indicates whether or not to remove multiple documents
1
2
3
4
5
6
7
8
9
10
11
12
13
yarn init

yarn init v1.22.19
question name (WEEK4VITE):
question version (1.0.0):
question description:
question entry point (index.js):
question repository url:
question author: Jaekyeong Jang
question license (MIT):
question private:
success Saved package.json
Done in 37.65s.
1
yarn add nodemon
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
yarn add v1.22.19
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 32 new dependencies.
info Direct dependencies
└─ nodemon@3.0.1
info All dependencies
├─ abbrev@1.1.1
├─ anymatch@3.1.3
├─ balanced-match@1.0.2
├─ binary-extensions@2.2.0
├─ brace-expansion@1.1.11
├─ braces@3.0.2
├─ chokidar@3.5.3
├─ concat-map@0.0.1
├─ debug@3.2.7
├─ fill-range@7.0.1
├─ glob-parent@5.1.2
├─ has-flag@3.0.0
├─ ignore-by-default@1.0.1
├─ is-binary-path@2.1.0
├─ is-extglob@2.1.1
├─ is-glob@4.0.3
├─ is-number@7.0.0
├─ lru-cache@6.0.0
├─ minimatch@3.1.2
├─ ms@2.1.3
├─ nodemon@3.0.1
├─ nopt@1.0.10
├─ normalize-path@3.0.0
├─ picomatch@2.3.1
├─ pstree.remy@1.1.8
├─ readdirp@3.6.0
├─ simple-update-notifier@2.0.0
├─ supports-color@5.5.0
├─ to-regex-range@5.0.1
├─ touch@3.1.0
├─ undefsafe@2.0.5
└─ yallist@4.0.0
Done in 1.08s.
1
yarn create vite

Select Framwork -> React TypeScript + SWC

cd vite-project yarn yarn dev

This post is licensed under CC BY 4.0 by the author.