2

I am looking for a way to perform MongoDB's upsert operation in waterline. One way is to use the native method.

Model.native(function (err, Collection){
    Collection.update({"key": "val"}, {"$set": {"x": "val"}}, {"upsert": true}, function (err, updated){
        // do something
    })
})

But if I don't want to use native, I could see on similar function findOrCreate, which creates a new entry if the item does not exist. However, I could not find a way to update the item if it exists. Is that possible or one has to use the native method only for that ?

Note: I am using Sails 0.11

Mandeep Singh
  • 7,674
  • 19
  • 62
  • 104

1 Answers1

4

As of now (v0.10.26) there is no way of doing a Mongo-style upsert besides the ones you've mentioned. This keeps coming up every once in a while but I couldn't find an issue addressing it directly, so maybe you could raise one.

Update
This issue talks about updateOrCreate and the linked threads suggest this might be added soon. I was looking into the Sails issues initially so no wonder I found nothing.

Community
  • 1
  • 1
galactocalypse
  • 1,905
  • 1
  • 14
  • 29