MongoDB - Array Update Operators

preview_player
Показать описание
In this video, shows you different operators on update an array value.

Рекомендации по теме
Комментарии
Автор

Have been looking for someone to actually teach how to push a value in the existing array in mongodb... It was very helpful Thanks :)

Asia_life_explorer
Автор

Thank you. Your videos are very informative n helpful

SaiKumar-tgct
Автор

This is the only good video I could find on this
thank you

ChrisFotosMusic
Автор

thank you very much for this training. i have problem with inserting data into array, i created array with MongoDB and would like to initialize it adding values. But with the method you use you do it with an "UPDATE" specifying the identifier. how to do? Thank you


function initial() {
var Document = ["CV", "Diplôme", "Certification", "Identité", "Autres", "Administration"]
Parameter.update(
{$push: {typeDocument: {$each: Document}}}
)
}



var mongoose = require('mongoose');
const { string } = require('rtf-parser');
//Stocker tous les champs de type select dans la base de données
var ParameterSchema = new mongoose.Schema({
typeDocument: {
index: true,
type: [String],
}

});

mongoose.model('Parameter', ParameterSchema);
module.exports = mongoose.model('Parameter');

ulrichnelson
Автор

is there is a way to update if an element from array is old and insert if new like this
{
"_id" : "1",
"nom" : "dali",
"traps" : [
{
"id" : "4",
"state" : "on",
"date" : "new"
},

{
"id" : "5",
"state" : "on",
"date" : "new"
}
]
}
for exemple for the traps.id 4 state become off
and if a new traps.id 6 comes it inserted to the db ?

dalilinkin
Автор

how to get popout value from array while update

rishavloomba
Автор

PLEASE HELP ME ON THIS ERROR IM STUCK FOR SOO LONG :



// MODEL

const mongoose = require("mongoose");
const Detail = mongoose.Schema({
brandName: String,
brandIconUrl: String,
details: String,
links: [
{
label: String,
url: String,
details: String,
},
],
});

module.exports = mongoose.model("detail", Detail);




// Template engine - Handlebars (Hbs)

<table id="Links">
<tr>
<th>Label</th>
<th>Url</th>
</tr>
{{#each details.links}}
<tr>
<div class="input-noBorder">
<td><input type="text" name="label" value="{{this.label}}"></td>
<td><input type="text" name="url" value="{{this.url}}"></td>
</div>
</tr>
{{/each}}
</table>


// CODE

try {
const data = req.body;
await Detail.updateMany(
{},

{
$set: {
brandName: req.body.brandName,
brandIconUrl: req.body.brandIconUrl,
'links.$[element].label': req.body.label,
'links.$[element].url': req.body.url,
},
}
);

res.redirect('/admin');
} catch (e) {
console.log(e.message);
res.redirect('/admin');
}




ERROR : Cast to string failed for value "[ '/', '/products', '/gallery', '/about', '/contact-us' ]" (type Array) at path "url"



shubhamjangid