lib/pancakes.mongo.adapter.js
function saveIndexInfo() {

    // reset the cache
    var tmpCache = cache.idxInfo;
    cache.idxInfo = {};

    var promises = [];

    // add promise for each things being saved/updated
    _.each(tmpCache, function (idxInfo, key) {
        var where = { str: key };
        var select = '_id count';

        var promise = IdxInfoModel.findOne(where, select).exec()
            .then(function (savedItem) {
                if (savedItem) {
                    return IdxInfoModel.findOneAndUpdate(where, { $inc: { count: idxInfo.count }});
                }
                else {
                    var model = new IdxInfoModel(idxInfo);
                    var deferred = Q.defer();
                    model.save(function (modelErr) {
                        modelErr ? deferred.reject(modelErr) : deferred.resolve(model.toObject());
                    });
                    return deferred.promise;
                }
            });

        promises.push(promise);
    });

    return Q.all(promises);
}
function saveIndexInfo() {

    // reset the cache
    var tmpCache = cache.idxInfo;
    cache.idxInfo = {};

    var promises = [];

    // add promise for each things being saved/updated
    _.each(tmpCache, function (idxInfo, key) {
        var where = { str: key };
        var select = '_id count';

        var promise = IdxInfoModel.findOne(where, select).exec()
            .then(function (savedItem) {
                if (savedItem) {
                    return IdxInfoModel.findOneAndUpdate(where, { $inc: { count: idxInfo.count }});
                }
                else {
                    var model = new IdxInfoModel(idxInfo);
                    var deferred = Q.defer();
                    model.save(function (modelErr) {
                        modelErr ? deferred.reject(modelErr) : deferred.resolve(model.toObject());
                    });
                    return deferred.promise;
                }
            });

        promises.push(promise);
    });

    return Q.all(promises);
}
function saveIndexInfo ( ) { // reset the cache var tmpCache = cache . idxInfo ; cache . idxInfo = { } ; var promises = [ ] ; // add promise for each things being saved/updated _ . each ( tmpCache , function ( idxInfo , key ) { var where = { str : key } ; var select = '_id count' ; var promise = IdxInfoModel . findOne ( where , select ) . exec ( ) . then ( function ( savedItem ) { if ( savedItem ) { return IdxInfoModel . findOneAndUpdate ( where , { $inc : { count : idxInfo . count } } ) ; } else { var model = new IdxInfoModel ( idxInfo ) ; var deferred = Q . defer ( ) ; model . save ( function ( modelErr ) { modelErr ? deferred . reject ( modelErr ) : deferred . resolve ( model . toObject ( ) ) ; } ) ; return deferred . promise ; } } ) ; promises . push ( promise ) ; } ) ; return Q . all ( promises ) ; }
Save a query to the idxInfo table
Save a query to the idxInfo table