Mongoosejs人口密集问题

时间:2014-06-29 23:18:46

标签: mongoose

我有一个代表用户的对象。 该对象将用户的注释,点等存储为数组 当我填充用户时,我会收到评论,点数等。但是在评论,点等内部还有更多字段

user:  { __v: 0,
 _id: 531f36ccccf511243bf9e0dc,
 avatar: '',
created: Thu Mar 13 2014 14:33:05 GMT+0000 (GMT),
lastUpdated: Thu Mar 13 2014 21:59:06 GMT+0000 (GMT),
currentLocation: 
 { _id: 5381eff2b3931c953a000133,
   position: { Long: -2.402307, Lat: 53.472664 },
   information: '<p>Rather nice, actually</p>',
   rating: 5,
   placename: 'little bridge',
   site: 'Barton Moss',
   spots: [ 5315f8b384119cb4362797f4 ] },
points: 1,
username: 'Jim the Twitcher',
google: {},
twitter: {},
facebook: {},
local: 
 { password: '***',
   email: '***' },
spots: 
  [ { lastUpdated: Tue Mar 04 2014 16:00:51 GMT+0000 (GMT),
   created: Tue Mar 04 2014 16:00:51 GMT+0000 (GMT),
   user: 531f36ccccf511243bf9e0dc,
   bird: 5315f8b384119cb4362797f6,
   location: 5381eff2b3931c953a000133,
   date: Tue Mar 04 2014 00:00:00 GMT+0000 (GMT),
   time: '16:00:51.574Z',
   _id: 5315f8b384119cb4362797f4,
   __v: 0 } ],
ranking: { position: 1, total: 2 },
comments: 
 [ { lastUpdated: Thu Mar 13 2014 22:38:38 GMT+0000 (GMT),
   created: Thu Mar 13 2014 22:38:38 GMT+0000 (GMT),
   comment: 'mum mum',
   source: 'BirdsApp',
   user: 531f36ccccf511243bf9e0dc,
   _id: 5322336e6db84e983355c31a,
   __v: 0 } ] }

如果你看'斑点',你可以看到没有填充'用户','鸟'和'位置'字段。

        process.nextTick(function() {
            User.findOne({
                'local.email': email
            }).populate({
                path: 'spots comments currentLocation'
            }).exec(function(err, user) {
                // console.log('first user: ', user);
                // console.log('actual user');
                // if there are any errors, return the error
                if (err)
                    return done(err);

                // if no user is found, return the message
                if (!user)
                    return done(null, false, req.flash('loginMessage', 'No user found.'));

                if (!user.validPassword(password))
                    return done(null, false, req.flash('loginMessage', 'Oops! Wrong password.'));

                // all is well, return user
                else
                    var opts = {
                        path: 'spots.bird',
                        model: 'Bird'
                    };
                User.populate(user, opts, function(err, user) {

                    if (err)
                        return done(err);

                    else
                        var opts = {
                            path: 'spots.location',
                            model: 'Location'
                        };
                    User.populate(user, opts, function(err, user) {
                        if (err)
                            return done(err);
                        else
                        //console.log('new user: ', user);
                            console.log(util.inspect(user, showHidden = false, depth = 5, colorize = true));
                        return done(null, user);
                    });
                });

            });
        });

...是我到目前为止所尝试过的。我知道人口密集是猫鼬的一个问题(而且我很难在某些层面上从概念上理解猫鼬)。我是这样做的,还是我必须以某种方式填充我在exec回调中收到的对象?

非常感谢任何帮助...

由于

詹姆斯

编辑:人口似乎工作正常,但正如我在@JohnnyHK的回复中所提到的,我认为不知何故它正在传递承诺对象,因为当我在我正在使用的dustjs表中打印它时我仍然只是得到objectID,即使我可以在控制台中看到它们......

0 个答案:

没有答案