Beruflich Dokumente
Kultur Dokumente
H. Moritsch 2022-04
SPENGERGASSE
Collection erzeugen
db.inventory.insertMany([
{ _id: "journal", qty: 25, size: { h: 14, w: 21, uom: "cm" },
status: "A" },
{ _id: "notebook", qty: 50, size: { h: 8.5, w: 11, uom: "in" },
status: "A" },
{ _id: "paper", qty: 100, size: { h: 8.5, w: 11, uom: "in" },
status: "D" },
{ _id: "planner", qty: 75, size: { h: 22.85, w: 30, uom: "cm" },
status: "D" },
{ _id: "postcard", qty: 45, size: { h: 10, w: 15.25, uom: "cm" },
status: "A" }
]);
Collection entfernen
db.inventory.drop();
db.inventory.find({ })
Prettyprint
db.inventory.find({ }).pretty()
db.inventory.find({ }).limit(3)
db.inventory.find({ }).skip(2)
db.inventory.find({ }).skip(2).limit(2)
db.inventory.count({ })
ODER
Negation
{ "size.uom": "in" }
Punkt-Operator verlangt Anführungszeichen!
{ "size.h": { $lt: 15 } }
Collection erzeugen
db.inventory.insertMany([
{ _id: "journal", qty: 25, tags: ["blank", "red"],
dim_cm: [ 14, 21 ] },
{ _id: "notebook", qty: 50, tags: ["red", "blank"],
dim_cm: [ 14, 21 ] },
{ _id: "paper", qty: 100, tags: ["red", "blank", "plain"],
dim_cm: [ 14, 21 ] },
{ _id: "planner", qty: 75, tags: ["blank", "red"],
dim_cm: [ 22.85, 30 ] },
{ _id: "postcard", qty: 45, tags: ["blue"],
dim_cm: [ 10, 15.25 ] }
]);
{ tags: "red" }
{ dim_cm: { $gt: 25 } }
Für mindestens ein Element müssen mehrere Bedingungen (gleichzeitig) erfüllt sein
{ "dim_cm.1": { $gt: 25 } }
Punkt-Operator verlangt Anführungszeichen!
{ tags: { $size: 3 } }
Nicht möglich: Kombination mit Vergleichsoperator { $size: { $gt: 1} }
Collection erzeugen
db.inventory.insertMany( [
{ _id: "journal", instock: [ { warehouse: "A", qty: 5 },
{ warehouse: "C", qty: 15 } ] },
{ _id: "notebook", instock: [ { warehouse: "C", qty: 5 }
] },
{ _id: "paper", instock: [ { warehouse: "A", qty: 60 },
{ warehouse: "B", qty: 15 } ] },
{ _id: "planner", instock: [ { warehouse: "A", qty: 40 },
{ warehouse: "B", qty: 5 } ] },
{ _id: "postcard", instock: [ { warehouse: "B", qty: 15 },
{ warehouse: "C", qty: 35 } ] }
]);
Für mindestens ein Element muss eine Bedingung – für ein Feld – erfüllt sein
{ "instock.qty": { $lte: 10 } }
Für ein bestimmtes Element muss eine Bedingung – für ein Feld – erfüllt sein
{ "instock.0.qty": { $lte: 10 } }
Collection
db.words.insertMany([
{ _id: 1, word: "hello"},
{ _id: 2, word: null },
{ _id: 3 },
])
{ word: null }
Dokumente abfragen
https://docs.mongodb.com/manual/tutorial/query-documents
JSON/BSON-Format
https://docs.mongodb.com/manual/core/document
MongoDB Shell
https://docs.mongodb.com/manual/mongo
Download: https://www.mongodb.com/try/download/shell
MongoDB Compass
https://www.mongodb.com/products/compass