R
R
riddlr2018-09-29 18:20:24
MongoDB
riddlr, 2018-09-29 18:20:24

How to modify Mongoose array without strict: false?

An incomprehensible situation. I get data from Monga I get an array with objects. Next, I need to modify each object in the array by adding a field to it. Seems like a simple task, but it doesn't work, the field is not added.
const tweets = await Tweet.find({author}).exec()

const proceedTweets = tweets.map(tweet => {
      Object.assign(tweet, {extra: 'stuff'})
      return tweet
    })

The array remains unchanged. Why is this happening and how can I modify the data received from the database?
ADF turned out Monguz does not return an ordinary array. There is an option to disable strict: false, but that doesn't work. What other options are there?
I just need to modify the search result in the database, and not the data itself in the database!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Pushkarev, 2018-09-29
@AXP-dev

const proceedTweets = tweets.map(tweet => ({ ...tweet, extra: 'stuff' }));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question