MongoDB in NodeJS - Arrays adding and removing elements (2020) [Episode #9]

preview_player
Показать описание
Let's go over how to add and remove elements from an array that is inside of MongoDB.

🙋‍♂️ Need help? Ask in our Discord community:

💡 Have an idea for a video or course? Request it here:

------------------------------

🕒 Timestamps:
00:00 Introduction
00:40 Adding to an array
03:09 Adding to an array only once
04:25 Deleting from an array
04:52 Outro

#discordjs #discordbots #wornoffkeys

FTC Legal Disclaimer - Some links found in my video descriptions might be affiliate links, meaning I will make commission on sales you make through my link. This is at no extra cost to you and it helps support the channel so I can make more free YouTube videos.
Рекомендации по теме
Комментарии
Автор

🔥 Get the code here:

🙋‍♂ Need help? Ask in our Discord community:
wornoffkeys.com/discord

WornOffKeys
Автор

You are a living MongoDB legend, in a single series you upgraded my MongoDB understanding

tukuyoma
Автор

very simple yet powerful explanation. Good job

keiferramos
Автор

Thank you so much💓💓💓 I'm new to mongoDB and I got stuck with removing array element... Now after watching this I understood the concept and solved my problem😀

dawnrahul
Автор

Thanks for the video, it was too helpful.

TheSummerPro
Автор

How do you remove only one element? I have two objects in an array and wish to remove only one.

andrewpasimio
Автор

simple clean explanation thanks a lot :-)
]

Ashish
Автор

what if i havenot created any document so i cant use findOneandUpadate so what i can do please suggest. this is my category schema
```
const categorySchema = new mongoose.Schema({
categories : [String]
});
```
initially this is empty so how can i fill this categories array .

PROTECHRAHUL
Автор

I have this schema
const MoedaSchema = new Schema({
valor: {
type: Number,
required: true,
},
usada: {
type: Boolean,
required: true,
},
});

const usuarioSchema = new Schema(
{
nome: {
type: String,
required: true,
unique: true,
},
moedas: [MoedaSchema],
},
{ timestamps: true }
);

When I $addToSet new moedas it allows copy, any idea how to solve or it just works for numbers array?

ellsonmendesYT
Автор

Hi bro
Ihave question
How to get array into datas like
[ joe, Hesam, jack ]
And choose one or how to check names i array to cant make duplicate names
Tnx ❤

hesamgh
Автор

I have one issue related that I have array of images I store images using multer, now my question is that when I checked the collection it seems like
Image :[
0: abd. Png,
1:xyz.png,
2 :aus.png]

So you to create api for updating Nd deleting bez on front end it seems will fetch all data can to help me out please how I will connect to you

bhojakrahul
Автор

Is there a way to prevent duplicates from getting in to a string array

vaiirecti
Автор

and how remove element in array using index?

nahueljj
Автор

can you please add a playlist how to make a job scheduling app in this scheduling app there should be built in tools drop-down that can be assigned for the job and also keep track of those tools if already assigned in mern stack with frontend and backend with mongodb data storage

mananbari
Автор

what if I have array of objects and I want to retrieve adn Update only 1 data

bhumit
Автор

And how to update old one with new data i am new in MongoDB

ansupari
Автор

Hey thatnks for the video. Very informative.

It doesnt seem to work for me though. When i look at the mongoose debugger upon request. It says "Mongoose: tracks.findOne({ _id: }, { new: true, projection: {} })". Im assuming it should be findOneAndUpdate, and not findOne?

SPROCKET
Автор

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
Автор

$push:{ modelList : req.body.modelList }
you taken from body instead of const data

DKForevergaming