How to insert or update an a array in MongoDB with Node.Js?
NickName:apinot Ask DateTime:2020-01-22T01:39:20

How to insert or update an a array in MongoDB with Node.Js?

I have a products collection where some products have this structure :

{
_id: anID
shops: 
[
  {
    _id : shopId,
    price: productsPrice
  },
  ...
]
}

I would like update the price of a given products and shop, but insert this shop with his price if it is not present in the array.

I'm a beginner with MongoDB.Working with Node.Js/express(mongoDB driver) but not using mongoose.

Thanks in advance

Copyright Notice:Content Author:「apinot」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/59846498/how-to-insert-or-update-an-a-array-in-mongodb-with-node-js

More about “How to insert or update an a array in MongoDB with Node.Js?” related questions

How to insert or update an a array in MongoDB with Node.Js?

I have a products collection where some products have this structure : { _id: anID shops: [ { _id : shopId, price: productsPrice }, ... ] } I would like update the price of a given

Show Detail

How to insert array of document in mongodb using node.js?

I want to insert array of document to mongodb using node.js but while inserting it's only inserting first data only. [{ "userid": "5664", "name": "Zero 2679", "number": &quo

Show Detail

Mongodb only insert if value is unique, else update - in node.js

I've started developing an app recently and have finally got my node.js server communicating with my mongodb database. I want to insert a bunch a JSON objects that look something like this: {...

Show Detail

how to update a mongodb document from node.js?

I am trying to update an array in a mongoDB from a node.js program. I am able to modify the array from within node.js, but I can not get the changes to save. http://pastebin.com/j0Mnf7jP I thin...

Show Detail

Update element in array if exists else insert new element in that array in MongoDb

I'm having group of array of element in MongoDB as given below : { "_id" : 5, "quizzes" : [ { "wk" : 1, "score" : 10 },

Show Detail

MongoDB and PHP - insert and update large PHP array

I have a loop and each time the loop iterates, it adds a record to an array. In my current model, I wait for the loop to finish completely and then insert that array into MongoDB and have not had

Show Detail

Procedural 2d-array mongoDB insert on node.js runs out of memory

I am trying to insert a 2000 x 2000 2d array into my mongoDB instance via my node.js server. Right now the way i'm doing it is: for (i=0; i<2000; i++){ //i = height of the tile ma...

Show Detail

MongoDB Insert Many, Update Many

I'm using MongoDB in node.js. I'm trying to update or insert many documents based on different conditions; however, MongoDB update (with upsert) only works with a single document or many documents ...

Show Detail

How do you insert an array of object into Mongodb node.js

Basically i want to insert into my Mongodb collection called "Events" an array of objects called "Events" with an id for each entry into the array. This is the result i want to get in json: { "

Show Detail

How to insert mongodb data from another js file - node.js -

I have watched and read loads of tutorials now on node.js and mongodb. I know how to create databases, Insert data, show that data on a ejs file, etc etc. However, I have no idea how to insert data...

Show Detail