-
Notifications
You must be signed in to change notification settings - Fork 0
/
mongo.txt
62 lines (43 loc) · 2.33 KB
/
mongo.txt
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
mongoDB is a database which does not use any set schema, that is, data is not stored in row column
fashion, but in a json file with hierarcies present in it
to install it first
brew install [email protected]
to install the latest mongoDB server code, this will install an executable, which has to
code to start the local mongoDB server
now to operate the server, we need a client and that is the mongosh client, which can be installed
using
brew install mongosh
and now to open mongoDB server each time, we can write the command
mongod --config /opt/homebrew/etc/mongod.conf
(these are all local to my machine)
to let the server open each time the system boots, write
brew services start mongodb/brew/[email protected]
(but lets just start the server manually each time)
then, letting the server run, we open another terminal window, and type in
mongosh
to start the mongosh client which directly interacts with the local server which has
a local address of
mongodb://localhost:27017
then install mongo compass which is a visual representation of whats happening in the
server and what and how many databases are running in the server
to connect the server to compass, just add the local address of the server to it, and everything
is set
some basic commands to run are
use name
this will switch to a new db or create one if it does not exist
then when we are in the database, we have to have a collection, and
that implicitely mentioned by using
db.collection_name.insertOne({json...})
this adds a single json entry onto the collection names collection_name. Collection is a
container or a group of documents within the database. collections are more like folders,
that group related json-like documents, and its json like, since its actually bson or
binary json.
so when we do
db.collection_name.insertOne({json...})
we insert a document into the collection_name collection, and documents within a collection
need not follow a certain scheme always, hence mongoDB is a schema-less database
js driver is a module that allows the js code to interact with a specific db, service,
system, and to ensure that a js code can access the mongodb server, we have to run the js
code through node.js and hence we have to install the mongoDB driver for node.js, which can be
done using
npm install mongodb