2

このクエリの結果をノード var オブジェクト「データ」に取得することは可能ですか? コンソールに正しい console.log(results) が表示されますが、結果がデータ変数に返されません。

var Metric = require('../metric');
var gViews = Object.create(Metric.prototype);
gViews.name = 'g_ref';
gViews.initialData = 0;

gViews.increment = function(results) {



var mongodb = require('mongodb');
var server = new mongodb.Server("127.0.0.1", 27017, {});

new mongodb.Db('xxxx', server, {}).open(function (error, client) {
    client.collection('xxxx_1', function(err, collection) {
        collection.insert({ref_domain:g}, function(err, docs) {
            collection.find({ref_domain: /g/}).count(function(err, results) {
                console.log(results);

            });
        });
    });
});
this.data;
};




module.exports = gViews;
4

1 に答える 1

0

設定するだけです。

var Metric = require('../metric');
var gViews = Object.create(Metric.prototype);
gViews.name = 'g_ref';
gViews.initialData = 0;

gViews.increment = function(results) {
    var mongodb = require('mongodb');
    var server = new mongodb.Server("127.0.0.1", 27017, {});

    new mongodb.Db('xxxx', server, {}).open(function (error, client) {
        client.collection('xxxx_1', function(err, collection) {
            collection.insert({ref_domain:g}, function(err, docs) {
                collection.find({ref_domain: /g/}).count(function(err, results) {
                    gViews.data = results;
                });
            });
        });
    });
};

module.exports = gViews;
于 2013-11-04T02:04:56.110 に答える