首页 > 代码库 > 与你相遇好幸运,Sailsjs查询

与你相遇好幸运,Sailsjs查询

sailsjs 原生查询

-------------------------------------

Lands.native(function(err, collection) {

if (err) return res.serverError(err);

collection.aggregate(

[{$group : {_id : "$QSDWMC", num_tutorial : {$sum : 1},}}]).toArray(function (err, results) {

if (err) return res.serverError(err);

done(null, results.length);//回调函数返回的是错误信息和结果

});

});

-----------------------------

Lands.native(function(err, collection) {

if (err) return res.serverError(err);

collection.aggregate(

[{$match: {

$and: [

{ $or: [ { isEdited: true }, { isEdited: "true" } ] },

{ZLDWMC: found[0]["ZLDWMC"] }]}},
 {
 $group : {
                        _id : null, signAcreage : {$sum :"$SHAPE_AREA"},signLandsNumber : {$sum :1},
                      }
                    }
                  ]
                ).toArray(function (err, results) {
                  if (err) return res.serverError(err);
                  sails.log.silly("===========================================");
                  sails.log.silly(results);
                  if(isEmptyObject(results)){
                    sails.log.silly("results isEmptyObject");
                    done(null, 0);
                  }else{
                    sails.log.silly(results[0]);
                    done(null, results[0]);
                  }
                });
              });

------------------------------------------

        Lands.update({OBJECTID:updatedRecord[‘object_id‘]},{isEdited:values[‘is_edited‘]}).exec(function (err,changedValues) {
          if (err) return res.serviceDBError("Lands DB Update Error",err);
          if (!changedValues || !changedValues.length || changedValues.length > 1) {
            return res.serviceError("changedValues Error",err);
          }
          res.ok(populatedRecord);
        });

-------------------------------------------

与你相遇好幸运,Sailsjs查询