Home > Net >  how to keep account of which user has posted which record in mongoDB database
how to keep account of which user has posted which record in mongoDB database

Time:12-06

I am working on MERN project, where users can post ads of their vehicles and other user can see these ads. I want that only the use who has submitted a vehicle ad will be allowed two delete that specific ad.I have to different mongoDB schema for user and vehicles ad and successfully storing and fetching users and vehicle data from mongoDB.I have no idea how this can be done. Can some guide me how it can be possible?

CodePudding user response:

You would add an identifier to your Vehicles collection to know which User is the owner of the Vehicle

{
  "_id": "12345",
  "description": "Vehicle for sell",
  "userId": "Your user _id goes here or any other unique identifier for user"
}

and then upon request to Update / Delete an ad you check whether requesting user has same id as userId in Vehicles collection.h

  • Related