db.Shirts.remove({});
db.Shirts.drop({});
db.Shirts.insertMany(
[
{
Brand:"Calvin",
Name: "Name 1",
Color: ["Blue", "Red"],
Price: 100,
Size: {
height:10, width:5
}
},
{
Brand:"Tommy",
Name: "Name 2",
Color: ["Blue", "Red", "Orange"],
Price: 10,
Size: {
height:10, width:5
}
}
,
{
Brand:"Calvin Kleins",
Name: "Name 3",
Color: ["Blue", "Red", "Orange"],
Price: 50,
Size: {
height:10, width:5
}
}
]
);
// related to: Update the Brand to Calvin Klein when you see only Calvin
db.Shirts.find( {Brand:"Calvin"} );
db.Shirts.find({Brand:{regex:/Calvin/}});
db.Shirts.find({Brand:"Calvin"});
db.Shirts.find({Brand:"Tommy"});
db.Shirts.updateMany({Brand:"Calvin"}, {$set:{Brand:"Calvin Klein"}} );
db.Shirts.find({});
db.Shirts.find(
{
Brand:"Calvin"
}
);
db.Shirts.find( {
Brand:{
$gt:2
}
}
);
// https://www.mongodb.com/docs/manual/reference/operator/query/regex/
db.Shirts.find({
Brand: { $regex: /Cal/ }
});
// Find Shirts that costs between 50 and 100
db.Shirts.find(
{
Price:
{
$gte:50, $lte:100
}
}
);
// Find Shirts that costs between 50 and 100
db.Shirts.find(
{
$and:[
{Price:{$gte:50}},
{Price:{$lte:100}}
]
}
);
// Find shirts where the color is Blue or Red
db.Shirts.find (
{
Color: {$in:["Red", "Blue"]}
}
);
Aug 07