Answer the question
In order to leave comments, you need to log in
How in Monge to write the value of an object's property to another property of the same object?
Strange title, I'll explain now. I have an object -
{
name: 'qwerty',
nameToo: '12345'
}
db.getCollection('collection').update({nameToo: {$exists:1}},{$set: {name: this.nameToo}}, {multi:true})
Answer the question
In order to leave comments, you need to log in
I don’t hear an answer, I also had to look for Pts for a long time in Google, I’ll write here, all of a sudden someone needs it)
db.getCollection('collection').find({
nameToo: {$exists:1}
}).forEach(
function (elem) {
db.getCollection('collection').update(
{
_id: elem._id
},
{
$set: {
name: elem.nameToo
}
}
);
}
);
update
name
find
name
$lookup + $out in aggregation pipe line is the
first thing that comes to mind if you want to do it in 1 query.
In general, combinations of operators depend on the difference between documents and the result you want to achieve. But the variations are practically unlimited.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question