Questions tagged [Mongoose] (359)

1
answer

Is it possible to update a number of records in the model of a mongoose?

Hello! Can I upgrade for just a few records? Now we have to do this sheet: array.forEach((item, i) => { User.updateOne( { id: item.id }, { $push: { history: { val: item.val } } }, () => {}) }) Is there a better option? Thank you in advance.
elnora_Blanda asked April 19th 20 at 12:42
1
answer

How to make action when change in mongodb node.js?

Hello! If there is any way we can follow the change collection and call of callback? long googled and found nothing Thank you in advance.
Madge.Spinka asked April 19th 20 at 11:59
0
answer

Why mongoose gives the hidden fields when creating new records?

In the model indicated select: false to the password field, but when you create a new user, the password will still be returned. Probably, this is the default behavior (although never noticed), but to register each field in the response is not very cool. There is a more succinct solution or is it a bug?
Lilyan_Run asked April 18th 20 at 12:44
1
answer

When prompted to findOneAndUpdate in mongoose duplicated $push, what's wrong?

When trying to add data in the database, $push somehow duplicate them in the field, ie a field with an array called dates to the database in the end should have 21 elements of an array after sending the data, now 42. Data is duplicated. Code a database query: router.post('/set-new-activities', async (req, res) => { con...
spencer_Johnston asked April 16th 20 at 11:05
1
answer

How to track changes in a mongoose model?

Hello I want to set the connection using sockets and send data from database to the client after every change. How to use mongoose I execute the function after each change to my collection
ward_Gottlieb asked April 16th 20 at 10:38
1
answer

In Mongoose to create a unique field?

I have a user schema like this: const userSchema = new Schema( { login: { type: String, required: true, unique: true }, passwd: { type: String, required: true } { timestamps: { createdAt: "created_at", updatedAt: "updated_at" } } ); const User = model("user", userSchema, 'user', true); In the documentation says ...
shad_Jakubowski asked April 9th 20 at 10:36
2
answers

How to pull the string from mongodb?

Hi all, I have added in the database data, which can not correctly display at ejs! Here is how I take data from dB: app.get('/ads/check',async (req,res,next) => { await Ads.find({}).then(result => { const login = req.session.login Res. render('check', { title: "Your ad on the website!", login: login, result }) }...
ted.Muraz asked April 9th 20 at 10:31
1
answer

How to access child properties?

is the object { "comments": 0, "_id": "5e7a142125a650dfa132b984", "title": "dasdadasd", "description": "dasdasdadasdasdasd", "author": { "_id": "5e7a142125a650dfa132b985", "name": "Artem", "userId": "5e7a0bea506a9edca2abaf6c" } } I need this code to access the userId: 1 Posts.find({ author: { userId: user._id } }...
archibald_Langosh asked April 9th 20 at 09:56
1
answer

How to search with full match on the array?

There is a model Schema({ members: [ { type: String, required: true, ref: "User" } ], createdAt: { type: Date, default: Date.now(), required: true }, lastMessage: { message: { type: String, required: true }, from: { type: String, required: true }, createdAt: { type: Date, required: true } }, messages: [ {...
mozell_Kuhlman asked April 8th 20 at 10:34
1
answer

How to add data to a specific user?

There is a page with users, when you click on user POPs modelka where I can for example write review for this user. How do I make it so that in DB this comment tied to a specific user? html <app-header></app-header> <section class="section friends"> <div class="container"> <div class="main-page-...
Allie_Feest asked April 8th 20 at 02:02