-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathw2_3_Node_MongoDB_MongooseODM
47 lines (37 loc) · 1.63 KB
/
w2_3_Node_MongoDB_MongooseODM
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
Node and MongoDB
--------------------
Node MongoDB Driver
---------------------
-> Node MongoDB Driver provided by the MongoDB developers;
-> Provides a high-level API for a Node application to interact with the MongoDB Server;
-> npm install mongodb --save
MongoDB Driver
---------------
-> The Node MongoDB driver supports several operations that can be performed from Node Application;
-> Connecting to a MongoDB;
-> Inserting, deleting, updating and querying documents;
-> Supports both callback and promise based interactions;
* ops -> array that returns the result;
----------------------------------------------------------------------------
Mongoose ODM
-------------
-> MongoDB stores data in the form of documnets;
-> No structure imposed on the document, any document can be stored in any collection;
-> If there is a requirement for the inserted documents in a collection to maintain a specific structure than MongooseODM is ideal choice;
-> Mongoose ODM - node module provides a lot of relational features for structuring the data/document;
ODM
-> Object Data Model
-> Object Document Mapping
-> Object relational mapping
-> Adds structure to MongoDB documents through schema;
-> Mongoose ODM node module is build over MongoDB;
-> Mongoose schema
-------------------------
* schema -> structure of the data stored;
* Defines all the fields of the document and their types; Can do validation;
* Schema types: String, Number, Date, Buffer, Boolean, Mixed, ObjectId, Array;
* Schema is used to create a Model function;
---------------------------------
use conFusion
db.users.find().pretty();
db.users.update({username:"admin"}, {$set: {admin:true}});