2

特定のスキルを持っている最寄りの労働者を彼の場所で見つけたいと思っています。

場所のスキーマ:

var schema = Schema({
    name: String,
    type: String, // home | latest
    user: {type: Schema.Types.ObjectId, ref: 'User'},
    address: String,
    position: {
        type: {type: String, default: 'Point'},
        coordinates: [Number]
    },
    status: String // active | inactive
}, {collection: 'locations'});

ワーカー スキーマ:

var schema = Schema({
    username: String,
    password: String,
    firstName: {type: String, default: ''},
    middleName: {type: String, default: ''},
    lastName: {type: String, default: ''},
    role: {type: String, default: 'user'}, // admin | user | worker
    skills: [{
        object: {type: Schema.Types.ObjectId, ref: 'Skill'},
        slug: String, // Should remove in the future
        ratePerHour: Number,
        status: {type: String, default: 'active'} // active | inactive
    }],
    locations: [{type: Schema.Types.ObjectId, ref: 'Location'}]
}, {collection: 'users'});

スキルスキーマ:

var schema = Schema({
    name: String,
    slug: String,
    users: [{type: Schema.Types.ObjectId, ref: 'User'}],
    isFeatured: Boolean,
    minRatePerHour: Number,
    maxRatePerHour: Number,
    status: String // active | inactive | deleted
}, {collection: 'skills'});

以下は私のクエリですが.where()、入力されたフィールドでは機能しません。

Location
    .find({
        'position': {
            $near: {
                $geometry: {type: 'Point', coordinates: [lat, lng]},
                $minDistance: 0,
                $maxDistance: 20000
            }
        }
    })
    .populate('user')
    .deepPopulate('user.skills.object')
    .where({'user.skills': {$elemMatch: {'object.slug': 'cleaning'}}})
    .limit(5)
    .exec(callback);

これらのスキーマを間違っていますか? ID 参照ではなく埋め込みドキュメントを使用する必要がありますか? 他に問い合わせる方法はありますか?

4

1 に答える 1