y
Size: a a a
Ꮶ
User.updateMany(
{}, // критерий фильтрации
{ $set: {referal: 0}},
{ upsert: true }, // параметр обновления
function(err, result){
console.log(result);
}
);
}Ꮶ
y
y
ВВ
ВВ
go
go
JD
find({createdAt: {$gte: date}}).sort({createdAt: -1}).limit(1)go
find({createdAt: {$gte: date}}).sort({createdAt: -1}).limit(1)JD
JD
JD
JD
JD
db.array15.findAndModify({
query: {
"some_id": 182315386
},
update: [
{
// Ensure that `docs` key is never null, otherwise $if will fail
$set: {
"docs": { $ifNull: [ "$docs", [] ] }
}
},
{
$set: {
"docs": {
$cond: {
// Check if sub-document with `type: 'wood'` already exists
if: {
$in: ["wood", "$docs.type"]
},
// If exists,
then: {
// then iterate over array of subdocuments in $doc
$map: {
input: "$docs",
as: "current",
in: {
$cond: {
// And when current subdocument got `type: 'wood'`
if: { $eq: ["$$current.type", "wood"] },
then: {
// Update current subdocument
$mergeObjects: [
"$$current",
{
// By adding 1 to the current value of qty
qty: { $sum: ["$$current.qty", 1] }
}
]
},
// Otherwise just return original subdocument
else: "$$current"
}
}
}
},
// If there is no subdocument,
else: {
// then just add the new subdocument to the `docs` array
$concatArrays: [
[ { type: "wood", qty: 1 } ],
"$docs"
]
}
} // $cond
} // "docs"
} // $set
}
],
upsert: true,
"new": true
})G

C
N