1

can someone help me add new items to a json object and the insert the new result to mongoDB, here is my json object

{
  image: "https://cdn-prd-02.com/sys-master/images/h1c/h3c/9351894368286/silo-6003901000319-front-335548_140Wx140H"
  name: "Boss Mature Captains Chicken 775g x 6"
  new_price: "R10794"
  old_price: "R13699"
},
{
  image: "https://cdn-prd-02.com/sys-master/images/h27/h17/9623589617694/silo-product-image-v2-01Nov2019-180040-6001889008532-front-382785-2_140Wx140H"
  name: "Ideas Double Hot Plate"
  new_price: "R11900"
  old_price: "R22900"
},
{
  image: "https://cdn-prd-02.com/sys-master/images/h94/h83/9529131663390/silo-product-image-v2-02Jul2019-180102-6002322013991-front-360000-24_140Wx140H"
  name: "Russell Hobbs Supremeglide Steam Iron"
  new_price: "R24900"
  old_price: "R25900"
},
{
  image: "https://cdn-prd-02.com/sys-master/images/h99/hd6/9258690871326/silo-6009523601514-front-312470_140Wx140H"
  name: "Purity Aqueous Cream Goodnight 325ml"
  new_price: "R2199"
  old_price: "R3299"
},
{
  image: "https://cdn-prd-02.com/sys-master/images/he4/hf2/9823222464542/silo-product-image-v2-26May2020-180139-6009523601460-up-426623-1762_140Wx140H"
  name: "Purity Baby Aqueous Cream 325ml"
  new_price: "R2199"
  old_price: "R3299"
},
{
  image: "https://cdn-prd-02.com/sys-master/images/h94/hc2/9732176904222/silo-product-image-v2-21Mar2020-180150-6009708050465-up-416097-1344_140Wx140H"
  name: "SCORE ENERGY DRINK ORIGINAL 500ML"
  new_price: "R999"
  old_price: "R1099"
},
{
  image: "https://cdn-prd-02.com/sys-master/images/h45/hbb/9195891654686/silo-4971850090250-front-280121_140Wx140H"
  name: "Casio Advanced Scientific Calculator"
  new_price: "R38400"
  old_price: "R54900"
}

so i basically want to add a new item after old_price called sale_type: "reduced", and then inset into the mongodb. I'm currently using

var user = new Parse.User();
user.set("name", $scope.Fullname);

to set another info to the DB.

1 Answer 1

2

to add new item sale_type to json object you can use

for(i=0;i<user.length;i++)
{
user[i].sale_type="reduced"
}

to insert into mongodb use

var client = require('mongodb').MongoClient;
var url = "";

client.connect(url, function(err, db) {
  if (err) throw err;
  var db = db.db("mydb");
  col = db.collection('myCol');
for(i=0;i<user.length;i++)
{
  col.insertOne(user[i], function(err, res) {
    if (err) throw err;
    console.log("1 document inserted");

  });
}
  db.close();
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.