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

Find in array (whereEqualOR) #116

Closed proft closed 7 years ago

proft commented 7 years ago

Hello!

Can I find documents by any value in array, for example in JS

const tags = ["tag1", "tag2"];
Messages.find({entity: entity, tag: {$in: tags}}, {sort: {created: 1}})

If I use whereEqual

Document[] documents = db.getCollection("Messages").whereEqual("tag", "tag1").whereEqual("tag", "tag2").whereEqual("entity", entityID).find();

then it filter all documents with tag = "tag1" AND then with tag = "tag2".

I want whereEqualOR() or whereInArray(field, array) :)

ocram commented 7 years ago

We'll add the following:

Query whereIn(String fieldName, Object[] fieldValues);

Thanks a lot for this suggestion -- it's indeed an important addition!

proft commented 7 years ago

Any date release? :)

PS: anyway thank you for this marvellous lib!

ocram commented 7 years ago

Today :)

The two new operators whereIn and whereNotIn should have been implemented in https://github.com/delight-im/Android-DDP/commit/103a8927d3620a4696a417a5ae8c193041f1767d now.

Can you try replacing the version v3.1.2 in your Gradle dependency with the following commit hash, please?

103a8927d3620a4696a417a5ae8c193041f1767d

Feedback would be much appreciated. Thanks!

Documentation in the README will be updated if this has been confirmed to work. Use arrays as value lists with these operators:

new String[] { "abc", "def", "ghi" }
// or
new Integer[] { 1, 2, 3 }
// or
// ...
proft commented 7 years ago

Works like a charm. I had one strange error about can't find interface ... but after Clean Project it works as I expect. Tested on two projects in different situations. It works! :) Thank you!

ocram commented 7 years ago

Thanks again!

Documentation has been added in https://github.com/delight-im/Android-DDP/commit/5efc88c368c15de447734eaad30b82c5335b9e0b and this feature is now included in the latest release.