How to filter array in subdocument with MongoDB [duplicate]

Using aggregate is the right approach, but you need to $unwind the list array before applying the $match so that you can filter individual elements and then use $group to put it back together: db.test.aggregate([ { $match: {_id: ObjectId(“512e28984815cbfcb21646a7”)}}, { $unwind: ‘$list’}, { $match: {‘list.a’: {$gt: 3}}}, { $group: {_id: ‘$_id’, list: {$push: ‘$list.a’}}} ]) … Read more

Why is `[` better than `subset`?

This question was answered in well in the comments by @James, pointing to an excellent explanation by Hadley Wickham of the dangers of subset (and functions like it) [here]. Go read it! It’s a somewhat long read, so it may be helpful to record here the example that Hadley uses that most directly addresses the … Read more

How to filter a Java Collection (based on predicate)?

Java 8 (2014) solves this problem using streams and lambdas in one line of code: List<Person> beerDrinkers = persons.stream() .filter(p -> p.getAge() > 16).collect(Collectors.toList()); Here’s a tutorial. Use Collection#removeIf to modify the collection in place. (Notice: In this case, the predicate will remove objects who satisfy the predicate): persons.removeIf(p -> p.getAge() <= 16); lambdaj allows … Read more

How to filter the jqGrid data NOT using the built in search/filter box

You problem can be very easy solved with respect of postData parameter including functions and trigger(‘reloadGrid’). I try explain the idea more detailed. Let us use mtype: “GET”. The only thing which standard search/filter box do after displaying the interface is appending of some additional parameters to the url, sending to server and reloading the … Read more

Remove rows with all or some NAs (missing values) in data.frame

Also check complete.cases : > final[complete.cases(final), ] gene hsap mmul mmus rnor cfam 2 ENSG00000199674 0 2 2 2 2 6 ENSG00000221312 0 1 2 3 2 na.omit is nicer for just removing all NA‘s. complete.cases allows partial selection by including only certain columns of the dataframe: > final[complete.cases(final[ , 5:6]),] gene hsap mmul mmus … Read more

Filter JSON by key value with JavaScript

you have to use lodash to group data, then map data var data = { “key”:”userSubscriptions”, “value”: [{“channel”:”Netflix”,”user”:”Bobby”,”region”:”NA”}, {“channel”:”Netflix”,”user”:”Bobby”,”region”:”EU”}, {“channel”:”Netflix”,”user”:”Jamie”,”region”:”SEA”}, {“channel”:”Prime Video”,”user”:”Bobby”,”region”:”NA”}] } var users = _.chain(data.value) .groupBy(“user”).map((value, key) => ({ user: key, data: value })).value(); users.forEach(element => { console.log(element) console.log(`${element.user}, your region subscriptions are: Netflix: ${element.data.map(c=>c.channel).join(‘,’)}, Prime Video: ${element.data.map(c=>c.region).join(‘,’)}`) });