12 mongo db_and_nodejs

15
MongoDB and Nodejs Ahmed Elbassel Email: [email protected] Skype: ahmed_elbassel

Transcript of 12 mongo db_and_nodejs

Page 1: 12 mongo db_and_nodejs

MongoDB and NodejsAhmed Elbassel

Email: [email protected]

Skype: ahmed_elbassel

Page 2: 12 mongo db_and_nodejs

MongoDB and Nodejs- MongoDB driver- Data Types- Connecting to MongoDB- Inserting Data with Node.js- Find or Query data with Nodejs- Update with Nodejs- Remove with Nodejs

Page 3: 12 mongo db_and_nodejs

MongoDB Driver- https://docs.mongodb.com/ecosystem/drivers/

Page 4: 12 mongo db_and_nodejs

Data types- Double- String- Object- Array- Binary data- Object id- Boolean- Date- Null- Regular Expression- Timestamp- 64-bit integer

Page 5: 12 mongo db_and_nodejs

3. Connecting to MongoDB- Go to the directory of your app.- Open a terminal > npm init- Create app.js file.- Run your app.

- Got an error :D- You have to install MongoDB driver- > npm install --save mongodb

Page 6: 12 mongo db_and_nodejs

4. Insert data with Node.js

Page 7: 12 mongo db_and_nodejs

5. Find or Query data with Node.js- Query by a field in a document:

Page 8: 12 mongo db_and_nodejs

5. Find or Query data with Node.js- Query by a field in subdocument:

Page 9: 12 mongo db_and_nodejs

5. Find or Query data with Node.js- Query by a field in array:

- Query by a field in array:

Page 10: 12 mongo db_and_nodejs

5. Find or Query with Nodejs- And operator:

- Or Operator

Page 11: 12 mongo db_and_nodejs

6. Update data with Node.js- Update Specific fields in one document to update all matched use

updateMany:

Page 12: 12 mongo db_and_nodejs

6. Update data with Node.js- Update Embedded field:

- Update Embedded field:

Page 13: 12 mongo db_and_nodejs

7. Remove data with Node.js- Remove one document:

- Remove all document:

Page 14: 12 mongo db_and_nodejs

For more information:

http://mongodb.github.io/node-mongodb-native/2.0/api/index.html

Page 15: 12 mongo db_and_nodejs

Questions