码迷,mamicode.com
首页 > Web开发 > 详细

与你相遇好幸运,Sailsjs查询

时间:2016-10-15 11:23:44      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:

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查询

标签:

原文地址:http://www.cnblogs.com/restful/p/5962933.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!