mWater/minimongo

remove() does not support a query

Closed this issue · 9 comments

Remove is defined as remove(id, success, error), where as mongo defines remove(<query>, {opts}) ... so a query would be nice.

Hint: for anyone trying remove({}), do a .removeCollection() then recreate it. or with a filter (remove with query): thecollection.find({filter as usual}).fetch((rows)=>rows.map((row)=>thecollection.remove(row._id)))

Oops, this is a huge limitation. Just fell into the trap that remove is not implemented properly. This should be mentioned in the Readme right away. I expected that at least the basic features of MongoDB are supported :-/

You are quite right! I've added a comment to the README pending a deeper change. The problem is that it would change the over-the-wire protocol and also make deleting all items far too easy (for our application). An interim solution would be to allow remove to take a filter that must specify an _id and throw otherwise? What would the REST side of things look like for a filtered remove?

Thanks for coming back on this. I'm not using minimongo in a REST context, it's just great for client side storage. And in this use case, remove without queries is a huge limitation. I'm now dropping the whole collection instead, as this is fine for my case. But for any serious development a working remove implementation would be vital IMHO.

I've added remove() and all seems to work fine. Do you also need remove(query, options, success, error)? If so, what are the possible options?

Yes, I would need a remove with queries, like such:

remove({somekey:'somevalue'})

I also noticed in the meantime that this is also not supported by upsert(). In Meteor's minimongo, you could use a query to select documents for the upsert and then change only those that match. An update() function would be helpful, too.

I worked around these limitations now, but the library would be much more useful if it provided the same (or nearly the same) API as Meteor's minimongo does. Maybe not all the details of the query language, but the basics at least, and query-based upsert(), update() and remove().

I've added remove({ somekey: 'somevalue'}), but I'm afraid that's all I have time for right now. I'm open to pull requests, however, and there is a very complete set of tests!

Thanks for taking your time. Glad that remove with a query has been implemented. Will this also work for a combination of query keys?

For the future, IMHO one of the most important missing things are
a) a true update and
b) a true upsert
with the capability to update an existing document based on a query.

Yes, it handles true query strings with multiple keys!

Great!