0

我有 2 个常见/模型:

  1. common/models/groups.json:示例:{_id: 1, name: "Root", "order": 1}
  2. common/models/counters.json:示例:{_id: "groups", seq: 0}

我有 2 个 common/models/*.js: 1. common/models/groups.js:

 module.exports = function(Groups) {
      Groups.observe('before save', function(context, next) {
        var _id = 'groups';
        var app = context.Model.app;
        if(context.isNewInstance) { 
          **var mongodb = app.dataSources.mongodb;
          var mongoConnector = app.dataSources.mongodb.connector;
          mongoConnector.collection("counters").findAndModify({_id: _id},
          [['_id','asc']], {$inc: {seq:1}}, {new: true}, function(error,
          sequence) {
            if(error) {
              throw error;
            } else {
              context.instance.id = sequence.value.seq.toString();
              next();
            }
          });**
        } else {
          next();
        }
      });
    };
  1. common/models/counters.js

    module.exports = 函数(计数器){};

创建组时,我需要找到计数器在哪里"groups" the latest id。并设置到我的customer _id by groups. 我该怎么做才能将箭头挡住其他js?

4

0 回答 0