How to remove duplicates based on a key in Mongodb?

This answer is obsolete : the dropDups option was removed in MongoDB 3.0, so a different approach will be required in most cases. For example, you could use aggregation as suggested on: MongoDB duplicate documents even after adding unique key. If you are certain that the source_references.key identifies duplicate records, you can ensure a unique index … Read more

How to count the consecutive duplicate values in an array?

It can be done simply manually: $arr = array(1,1,1,2,2,3,3,1,1,2,2,3); $result = array(); $prev_value = array(‘value’ => null, ‘amount’ => null); foreach ($arr as $val) { if ($prev_value[‘value’] != $val) { unset($prev_value); $prev_value = array(‘value’ => $val, ‘amount’ => 0); $result[] =& $prev_value; } $prev_value[‘amount’]++; } var_dump($result);

How to do unique constraint works with NULL value in MySQL

No, MySQL is doing the right thing, according to the SQL-99 specification. https://mariadb.com/kb/en/sql-99/constraint_type-unique-constraint/ A UNIQUE Constraint makes it impossible to COMMIT any operation that would cause the unique key to contain any non-null duplicate values. (Multiple null values are allowed, since the null value is never equal to anything, even another null value.) If you … Read more