MongoDB如何去除组合重复项

sql server有下列语句:


// 查找名字性别唯一的学生

select distinct name,sex from student


// 转换成MongoDB的话,我怎么把这种组合列去重,MongoDB好像只支持单个field的去重

db.student.distinct("name"); // 只支持一个field

db.student.distinct("name","sex"); // 错误的,不支持多个field的组合去重


有没有大神解决过类似问题,求指导.................


慕婉清6462132
浏览 700回答 2
2回答

大话西游666

collection = db.tb;result = collection.aggregate(             [                {"$group": { "_id": { market: "$market", code: "$code" } } }            ]        );printjson(result);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

MongoDB