如何记录哪个用户在 mongoDB 数据库中发布了哪条记录

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

我正在从事 MERN 项目,用户可以在其中 post 他们车辆的广告,其他用户可以看到这些广告。我希望只允许提交车辆广告的用户两次删除特定 ad.I 必须针对用户和车辆广告的不同 mongoDB 架构,并成功地从 [= 存储和获取用户和车辆数据14=] 不知道如何做到这一点。有人可以指导我如何实现吗?

您可以在 Vehicles collection 中添加一个标识符,以了解哪个 UserVehicle

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

然后根据请求更新/删除 ad 您检查请求用户是否与 Vehicles collection.h

中的 userId 具有相同的 ID