如何根据字段组合提取唯一数据

时间:2016-03-21 06:57:32

标签: node.js mongodb mongoose

我的架构是

var FlatSchema = new Schema({
    tower: { type: Schema.ObjectId, ref: "Tower" },
    project: { type: Schema.ObjectId, ref: "Project" },
    status: String,
    floor: Number,
    size: String,
    type: String,
    flat_number: String,
    price: Number,
    price_per_unit: Number,
    carpetArea: Number,
    directionFacing: String,
    livingRoomArea: Number,
    kitchenArea: Number,
    balconies: Number,
    bathRooms: Number,
    furnishingState: String,
    flooringType: String,
    FloorPlans_2d: String,
    FloorPlans_3d: String,
    createdAt: { type: Date, 'default': Date.now },
    isDeleted: { type: Boolean, 'default': false }
});

我想获取项目ID等于给定id的所有单位,并且结果在rugArea和type的基础上是唯一的。

Flat.find({ project: req.params.project, isDeleted: false}, function(err, flats) {
        if (err) { return res.status(500).send(err); }
        if (!flats) { return res.json(401); }
        res.status(200).json(flats);
    });

你可以编辑我的查询以获得所需的结果吗?

1 个答案:

答案 0 :(得分:0)

rootView.findViewById(R.id.my_recycler_view); carpetArea的基础上获得唯一性的一种方法是aggregation,示例代码为

type