distinct-values

C# MongoDB Distinct Query Syntax

五迷三道 提交于 2019-11-29 10:52:59
I am trying to get the distinct values from a field in MongoDB. I am having real trouble with the Syntax. Using mongoshell it's relatively easy to do, this is the query I run: db.cmstest.distinct("categories") This query returns an array of strings with all the distinct values. Now I am trying to get the syntax right using the latest official MongoDB Drivers, but not to much success. This is my code, which is unsuccessful: var categoriesList = await blogContext.Articles.DistinctAsync<List<string>>("categories", ""); Mind you categories is a List<string> . Could anyone help shed some light? I

java 8 how to get distinct list on more than one property

安稳与你 提交于 2019-11-29 06:55:20
How can one get the distinct (distinct based on two property) list from a list of objects. for example let there are list of objects with property name and price. Now how can I get a list with distinct name or price. suppose list<xyz> l1 = getlist(); // getlist will return the list. Now let l1 has the following properties(name, price) :- n1, p1 n1, p2 n2, p1 n2, p3 Now after the filter the list should be- n1, p1 n2, p3 I tried solving like this - public List<xyz> getFilteredList(List<xyz> l1) { return l1 .stream() .filter(distinctByKey(xyz::getName)) .filter(distinctByKey(xyz::getPrice))

List distinct values in a vector in R

半世苍凉 提交于 2019-11-28 21:45:48
问题 How can I list the distinct values in a vector where the values are replicative? I mean, similarly to the following SQL statement: SELECT DISTINCT product_code FROM data 回答1: Do you mean unique : R> x = c(1,1,2,3,4,4,4) R> x [1] 1 1 2 3 4 4 4 R> unique(x) [1] 1 2 3 4 回答2: If the data is actually a factor then you can use the levels() function, e.g. levels( data$product_code ) If it's not a factor, but it should be, you can convert it to factor first by using the factor() function, e.g. levels

How to get a cursor with distinct values only?

旧巷老猫 提交于 2019-11-28 08:43:12
问题 I want to return a cursor only with distinct values of a column. The column 'Groups' has more items but with only 2 values: 1,2,1,1,1,2,2,2,1 String[] FROM = {Groups,_ID}; public Cursor getGroups(){ //...... return db.query(TABLE_NAME,FROM,null,null,null,null,null); } will return a cursor containing {1,2,1,1,1,2,2,2,1} but I would like to contain just {1,2}. 回答1: You can have an sql query like this, public Cursor usingDistinct(String column_name) { return db.rawQuery("select DISTINCT "+column

C# MongoDB Distinct Query Syntax

青春壹個敷衍的年華 提交于 2019-11-28 04:32:21
问题 I am trying to get the distinct values from a field in MongoDB. I am having real trouble with the Syntax. Using mongoshell it's relatively easy to do, this is the query I run: db.cmstest.distinct("categories") This query returns an array of strings with all the distinct values. Now I am trying to get the syntax right using the latest official MongoDB Drivers, but not to much success. This is my code, which is unsuccessful: var categoriesList = await blogContext.Articles.DistinctAsync<List

How to maintain a Unique List in Java?

99封情书 提交于 2019-11-28 03:52:51
How to create a list of unique/distinct objects (no duplicates) in Java? Right now I am using HashMap<String, Integer> to do this as the key is overwritten and hence at the end we can get HashMap.getKeySet() which would be unique. But I am sure there should be a better way to do this as the value part is wasted here. Frank You can use a Set implementation: Some info from the JAVADoc: A collection that contains no duplicate elements . More formally, sets contain no pair of elements e1 and e2 such that e1.equals(e2), and at most one null element. As implied by its name, this interface models the

Selecting distinct 2 columns combination in mysql

亡梦爱人 提交于 2019-11-27 20:32:26
I have a mysql table that looks like this: 1 value1 value2 3534 2 value1 value1 8456 3 value1 value2 3566 4 value1 value3 7345 5 value2 value3 6734 I need a query to select all the rows with distinct column 2 and 3, for example the output I want for this example will look like this: 1 value1 value2 3534 2 value1 value1 8456 4 value1 value3 7345 5 value2 value3 6734 i've found a few samples on how to do it but they all select distinct on each column individually. Assuming that the first column is unique, you can do this: SELECT id, col2, col3, col4 FROM yourtable WHERE id IN ( SELECT MIN(id)

Given a number, produce another random number that is the same every time and distinct from all other results

心已入冬 提交于 2019-11-27 09:46:46
Basically, I would like help designing an algorithm that takes a given number, and returns a random number that is unrelated to the first number. The stipulations being that a) the given output number will always be the same for a similar input number, and b) within a certain range (ex. 1-100), all output numbers are distinct. ie., no two different input numbers under 100 will give the same output number. I know it's easy to do by creating an ordered list of numbers, shuffling them randomly, and then returning the input's index. But I want to know if it can be done without any caching at all.

Use of Distinct with list of custom objects

≯℡__Kan透↙ 提交于 2019-11-27 07:41:28
问题 How can I make the Distinct() method work with a list of custom object ( Href in this case), here is what the current object looks like: public class Href : IComparable, IComparer<Href> { public Uri URL { get; set; } public UrlType URLType { get; set; } public Href(Uri url, UrlType urltype) { URL = url; URLType = urltype; } #region IComparable Members public int CompareTo(object obj) { if (obj is Href) { return URL.ToString().CompareTo((obj as Href).URL.ToString()); } else throw new

Selecting distinct 2 columns combination in mysql

时光毁灭记忆、已成空白 提交于 2019-11-27 04:27:28
问题 I have a mysql table that looks like this: 1 value1 value2 3534 2 value1 value1 8456 3 value1 value2 3566 4 value1 value3 7345 5 value2 value3 6734 I need a query to select all the rows with distinct column 2 and 3, for example the output I want for this example will look like this: 1 value1 value2 3534 2 value1 value1 8456 4 value1 value3 7345 5 value2 value3 6734 i've found a few samples on how to do it but they all select distinct on each column individually. 回答1: Assuming that the first