delight-im / Android-DDP

[UNMAINTAINED] Meteor's Distributed Data Protocol (DDP) for clients on Android
Apache License 2.0
274 stars 54 forks source link

Meteor.update() access denied #28

Closed kkm closed 9 years ago

kkm commented 9 years ago

Hi @mwaclawek Is known not finished yet?

Serverside.js

mongodb.allow({
  remove : function() {
    return true;
  },
  update : function(userId, doc, fields, modifier) {
    return true;
  },
  insert : function() {
    return true;
  }
});

Java

Map<String, Object> updateQuery = new HashMap<String, Object>();
updateQuery.put("_id", "r87MfSvjMdaD9J8Lh");
Map<String, Object> updateValues = new HashMap<String, Object>();
Map<String, Object> options = new HashMap<String, Object>();
updateValues.put("some-number", 5);
DDP.mMeteor.update("mongodb", updateQuery, updateValues)

LogCat:

09-12 06:25:37.078: I/tikatoy(27287): DDP: Update fail: Access denied. In a restricted collection you can only update documents, not replace them. Use a Mongo update operator, such as '$set'.

Thanks for the answer.

ocram commented 9 years ago

Thanks for reporting this!

As far as I know, when you define allow or deny rules for your collection, this turns the collection into a "restricted collection".

Now if you run update(...) without any modifiers or operators, this replaces the old document. And this is not allowed in a restricted collection.

If you want to run an update which does not replace but amend the old document, you have to wrap the updateValues in a map with the $set key.

Learn more here: http://docs.mongodb.org/manual/reference/operator/update/set/

Does that help?