Angular 10 JSON Data Not Working When Adding to MongoDB

Viewed 26

Hello I have completed coding for my fake back-end using json-server. Things are working the way I expect for the e-commerce site on the front end. Now preparing to use MongoDB for production on back end using the db.json file and trying to import with compass does not work. According to json-server documentation my data is correct.

The error I get when trying to import is "Operations passed in cannot be an array." I also used a tool to un-format an format with validation in which I copied my JSON data, I get an error "That doesn't appear to be valid JSON. Validation failed with the following error:"

What I don't understand why this works on Angular 10. All the code I written so far is based on this db.json file. I also manually tried to add data into MongoDB, see below:

 db.collection.insertMany([{
"products":[
{

}
]
}
{) 

It takes it but it never adds my object (products) when I view it using .find().pretty. Viewing it in compass it has products as an array

Can someone please explain to my what is going on and what I need to do or point me in the right direction. I'm new to MongoDB, its not getting my objects. I have included my db.json file. As I stated my entire front end is based on this structure of JSON.

db.json

{
  "products": [
    {
      "_id": 1,
      "name": "Overalls",
      "size": " ",
      "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
      "imageUrl": "http://localhost:4200/assets/overalls.png",
      "price": 250
    },
    {
      "_id": 2,
      "name": "Red Onepiece",
      "size": " ",
      "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
      "imageUrl": "http://localhost:4200/assets/redonepiece-r.png",
      "price": 160
    },
    {
      "_id": 3,
      "name": "Sport",
      "size": " ",
      "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
      "imageUrl": "http://localhost:4200/assets/sportoutfit.png",
      "price": 50
    },
    {
      "_id": 4,
      "name": "Purple Outfit",
      "size": "",
      "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
      "imageUrl": "http://localhost:4200/assets/purpleoutfit4.png",
      "price": 100
    },
    {
      "_id": 5,
      "name": "Pink To Slick",
      "size": "",
      "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
      "imageUrl": "http://localhost:4200/assets/PinkToSlick.png",
      "price": 299
    },
    {
      "_id": 8,
      "name": "Grey Jumper",
      "size": "",
      "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
      "imageUrl": "http://localhost:4200/assets/greyofftheshoulder.png",
      "price": 99
    },
    {
      "_id": 9,
      "name": "Crop Jacket",
      "size": " ",
      "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
      "imageUrl": "http://localhost:4200/assets/slickjacket.png",
      "price": 299
    },
    {
      "_id": 10,
      "name": "Shear Top",
      "size": "",
      "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
      "imageUrl": "http://localhost:4200/assets/sexy.png",
      "price": 299
    },
    {
      "_id": 11,
      "name": "Blueprint One Piece",
      "size": " ",
      "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
      "imageUrl": "http://localhost:4200/assets/Extra-n-Blue.png",
      "price": 199
    },
    {
      "_id": 12,
      "name": "BabyGirl Jogger",
      "size": " ",
      "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
      "imageUrl": "http://localhost:4200/assets/BabyGirl.png",
      "price": 99
    },
    {
      "_id": 13,
      "name": "Black One Piece",
      "size": " ",
      "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
      "imageUrl": "http://localhost:4200/assets/BlacknwhiteOne.png",
      "price": 199
    }
    
  ],
  "wishlist": [
    {
      "id": 25
    },
    {
      "id": 65
    },
    {
      "id": 67
    },
    {
      "id": 70
    },
    {
      "id": 72
    },
    {
      "id": 29
    },
    {
      "id": 35
    },
    {
      "id": 71
    },
    {
      "id": 30
    },
    {
      "id": 27
    },
    {
      "id": 21
    },
    {
      "id": 1
    },
    {
      "id": 2
    },
    {
      "id": 3
    },
    {
      "id": 4
    },
    {
      "id": 6
    },
    {
      "id": 8
    }
  ],
  "wishlistitem": [
    {
      "product": {
        "id": 8,
        "name": "Grey Jumper",
        "size": "",
        "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
        "imageUrl": "http://localhost:4200/assets/greyofftheshoulder.png",
        "price": 99
      },
      "id": 1
    }
  ],
  "cart": [
    {
      "product": {
        "id": 2,
        "name": "Red Onepiece",
        "size": "S",
        "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
        "imageUrl": "http://localhost:4200/assets/redonepiece-r.png",
        "price": 160
      },
      "id": 1
    },
    {
      "product": {
        "_id": 8,
        "name": "Grey Jumper",
        "size": "L",
        "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
        "imageUrl": "http://localhost:4200/assets/greyofftheshoulder.png",
        "price": 99
      },
      "id": 3
    }
  ],
  "purses": [
    {
      "id": 150,
      "name": "Black-Louis Vuitton",
      "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
      "imageUrl": "http://localhost:4200/assets/IMG-20211019-WA0003.png",
      "price": 250
    },
    {
      "id": 151,
      "name": "BlackBlue",
      "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
      "imageUrl": "http://localhost:4200/assets/IMG-20211017-WA0008.png",
      "price": 300
    },
    {
      "id": 152,
      "name": "White",
      "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
      "imageUrl": "http://localhost:4200/assets/IMG-20211017-WA0013.png",
      "price": 300
    },
    {
      "id": 153,
      "name": "Brown-Louis Vuitton",
      "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
      "imageUrl": "http://localhost:4200/assets/IMG-20211019-WA0002.png",
      "price": 300
    },
    {
      "id": 154,
      "name": "Green Small Louis Vuitton",
      "description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
      "imageUrl": "http://localhost:4200/assets/IMG-20211019-WA0010.png",
      "price": 350
    }
  ],
  "shoes": [],
  "posts": [
    {
      "id": 1,
      "title": "json-server",
      "author": "typicode"
    }
  ],
  "comments": [
    {
      "id": 1,
      "body": "some comment",
      "postId": 1
    }
  ],
  "profile": {
    "name": "typicode"
  }
}
0 Answers
Related