products.insertMany
an anonymous user
·
MongoDB
db.createCollection("products");
db.products.insertMany([
{ _id: ObjectId("65b8b63b4c2a33895bdd61f5"), name: "Hat", onSale: true },
{ _id: ObjectId("65b8b63b4c2a33895bdd61f6"), name: "Scarf"},
{ _id: ObjectId("65b8b63b4c2a33895bdd61f7"), name: "Gloves", onSale: false},
{ _id: ObjectId("65b8b63b4c2a33895bdd61f8"), name: "Shoes"}
]);
db.products.find({});
db.products.updateMany({},
[
{
$set: {
onSale: {
"$cond": {
"if": {
"$in": [
"$_id",
[
ObjectId("65b8b63b4c2a33895bdd61f7"),
ObjectId("65b8b63b4c2a33895bdd61f8")
]
]
},
"then": true,
"else": false
}
}
}
},
]
);
db.products.find({});
Output
Embed on website
To embed this program on your website, copy the following code and paste it into your website's HTML:
Comments
This comment belongs to a banned user and is only visible to admins.
This comment belongs to a deleted user and is only visible to admins.