Day 01 Foundations

Documents, Collections, and CRUD

Install MongoDB, understand the document model, and perform all four CRUD operations from the shell and from Node.js.

~1 hour Hands-on Precision AI Academy

Today’s Objective

Install MongoDB, understand the document model, and perform all four CRUD operations from the shell and from Node.js.

MongoDB stores data as BSON (Binary JSON) documents. A document is like a row in SQL — but it can have nested objects and arrays. No fixed schema required.

Install and connect
INSTALL AND CONNECT
# Mac: brew install mongodb-community
# Linux: see mongodb.com/docs/manual/installation
# Or use MongoDB Atlas free tier (cloud)

# Start the shell
mongosh
mongosh CRUD
MONGOSH CRUD
// Select database (creates if doesn't exist)
use myapp

// INSERT
db.users.insertOne({ name: 'Alice', age: 28, role: 'admin' })
db.users.insertMany([ { name: 'Bob', age: 32 }, { name: 'Carol', age: 25 }
])

// FIND
db.users.find() // all documents
db.users.findOne({ name: 'Alice' })
db.users.find({ age: { $gte: 28 } })  // age >= 28

// UPDATE
db.users.updateOne( { name: 'Alice' }, { $set: { role: 'superadmin' } }
)

// DELETE
db.users.deleteOne({ name: 'Carol' })
db.users.deleteMany({ age: { $lt: 18 } })
Every document gets an _id field automatically. It's a 12-byte ObjectId that encodes a timestamp. You can use it to sort documents by creation time without storing a separate createdAt field: .sort({ _id: -1 }).
📝 Day 1 ExerciseInsert and Query Documents
  1. C
  2. r
  3. e
  4. a
  5. t
  6. e
  7. a
  8. d
  9. a
  10. t
  11. a
  12. b
  13. a
  14. s
  15. e
  16. a
  17. n
  18. d
  19. c
  20. o
  21. l
  22. l
  23. e
  24. c
  25. t
  26. i
  27. o
  28. n
  29. f
  30. o
  31. r
  32. p
  33. r
  34. o
  35. d
  36. u
  37. c
  38. t
  39. s
  40. .
  41. I
  42. n
  43. s
  44. e
  45. r
  46. t
  47. 1
  48. 0
  49. s
  50. a
  51. m
  52. p
  53. l
  54. e
  55. p
  56. r
  57. o
  58. d
  59. u
  60. c
  61. t
  62. s
  63. w
  64. i
  65. t
  66. h
  67. n
  68. a
  69. m
  70. e
  71. ,
  72. p
  73. r
  74. i
  75. c
  76. e
  77. ,
  78. c
  79. a
  80. t
  81. e
  82. g
  83. o
  84. r
  85. y
  86. ,
  87. a
  88. n
  89. d
  90. i
  91. n
  92. S
  93. t
  94. o
  95. c
  96. k
  97. f
  98. i
  99. e
  100. l
  101. d
  102. s
  103. .
  104. Q
  105. u
  106. e
  107. r
  108. y
  109. :
  110. a
  111. l
  112. l
  113. p
  114. r
  115. o
  116. d
  117. u
  118. c
  119. t
  120. s
  121. ,
  122. p
  123. r
  124. o
  125. d
  126. u
  127. c
  128. t
  129. s
  130. u
  131. n
  132. d
  133. e
  134. r
  135. $
  136. 5
  137. 0
  138. ,
  139. p
  140. r
  141. o
  142. d
  143. u
  144. c
  145. t
  146. s
  147. i
  148. n
  149. s
  150. t
  151. o
  152. c
  153. k
  154. ,
  155. p
  156. r
  157. o
  158. d
  159. u
  160. c
  161. t
  162. s
  163. b
  164. y
  165. c
  166. a
  167. t
  168. e
  169. g
  170. o
  171. r
  172. y
  173. .

Supporting Resources

Go deeper with these references.

MongoDB Docs
Official MongoDB Manual Complete reference documentation for all MongoDB features and operations.
MongoDB University
Free MongoDB Courses Official free courses on MongoDB fundamentals, aggregation, and performance.
GitHub
MongoDB Driver Examples Official Node.js and Python driver examples on GitHub.

Day 1 Checkpoint

Before moving on, make sure you can answer these without looking:

Continue To Day 2
Queries and Operators