Zusammenfassung der Ressource
MongoDB Notes
- Schema-Free
- Hierarchy
- Instance
- Database
- Collection
- Document
- Every Document
has an id
- JSON Format
- Embedded
- Attributes are not
stored in separate
collection
- Implementation depends on
the needs of the application
- Linked
- Optimized to quickly retrieve
relevant data
- Design should take into account
how the application needs the data
- Documentation: https://docs.mongodb.com/manual/
- Extensions
- Mongoose
- RoboMongo
- MongoChef
- CRUD Operations
- find
- Equivalent to SELECT statement
- Examples
- Minimal
- db.Products.find()
- Query + Projection
- db.Products.find({ "desc": "42in TV", "width": 41 })
- Query Only
- db.Products.find({"desc": "42in TV"})
- Projection Only
- db.Products.find({"width": 1, "height": 1, "depth": 1} )
- Arrays
- db.Products.find({ "priceHist" : {$elemMatch: { $gt: 100, $lt: 300 } } })
- Conditional Statements
- db.Products.find({"reviews.star": { $gte: 4 } })
- Embedded Collections
- db.Products.find({"editorReview.authorlname" : "Smith"} )
- Syntax
- db.collection.find(query, projection)
- Projection: Which columns
you're going to return
- id always comes back
unless id is set to false
{id: 0}
- Inserts
- Examples
- Single
- db.Questions.insert({"_id": NumberInt(5), "prodID": NumberInt(4), "author": "MrsInquisitive", "text": "Sample question"})
- Multiple
- db.Questions.insert([{"_id": NumberInt(6), "prodID": NumberInt(4),
"author": "MrsInquisitive", "text": "Sample question"}, {"_id":
NumberInt(7), "prodID": NumberInt(4), "author":
"MrIWantToKnow", "text": "Sample question"} ])