[solved] If record exist, update if not create new - how to achieve this in meteor?

{
  "_id": "W4ZZxraDXGj3FtJek",
  "name": "Rust",
  "description": "new programming language by google",
  "organization": "rYefzmKDCoqKJQmeA",
  "status": "active",
  "dateAdded": "2018-02-07T13:51:31.564Z",
  "members": [
    {
      "id": "6BuSTu6GZybkmozWW",
      "role": "manager",
      "hours": "",
      "dateAdded": "2018-02-07T15:13:30.654Z",
      "reports": [
        {
          "date": "2018-02-06T12:39:32.118Z",
          "hours": "19123"
        },
        {
          "date": "2018-02-05T12:39:32.118Z",
          "hours": "19123"
        }
      ]
    },
{
      "id": "aFJlejSTu6erawlkjeru",
      "role": "manager",
      "hours": "",
      "dateAdded": "2018-02-07T15:13:30.654Z",
      "reports": [
        {
          "date": "2018-02-06T12:39:32.118Z",
          "hours": "19123"
        }
        }
      ]
    }
  ]
}

I have a collection like this. What I want to do is search a project by ID, search a single member and find a specific report based on date property. If it is found, I want to update the hours. If it’s not, I want to create a new report object.

I’m creating a test app to learn meteor. Currently new to meteor and NoSQLs (mongoDB)

Thanks for the help :smile:

Are you looking for this? https://docs.meteor.com/api/collections.html#Mongo-Collection-upsert

2 Likes

What I did for the meantime is make a query. check if it returns something then do what i want. Thanks for this.