MongoDB select distinct and where
问题 So I'm doing a select distinct which works, but I also want to add another key. $data = $this->db->command(array("distinct" => "scores","key"=>"target_user")); I need something like this: SELECT DISTINCT target_user FROM scores where seen = 1 Can it be done in mongo? 回答1: You can do it as follows by using distinct query : db.scores.distinct("target_user", {"seen":1}) Running distinct query using Aggregate Framework is shown below. Inserted following records into MongoDB. db.scores.insert(