sql >> データベース >  >> NoSQL >> MongoDB

マングースのポピュレートクエリからnull値を除外する方法

    最後に、ここで集計を使用する必要がありました。他のオプションはありません。

    スキーマを変更する必要はありません

    var results =await dbo.collection('mediators').aggregate([
         { $lookup:
             {
               from: 'venues',
               localField: 'venue',
               foreignField: '_id',
               as: 'venue'
             }
          },
            $match:{$and:[{"venue.venue_type":req.query.venue_type} , {"venue.capacity":{$gte:parseInt(req.query.capacitylb) , $lte:parseInt(req.query.capacityub)}}]}
          },{
            $lookup:
             {
               from: 'users',
               localField: 'user',
               foreignField: '_id',
               as: 'user'
             }
          },{
            $lookup:
            {
               from: 'professionals',
               localField: 'professional',
               foreignField: '_id',
               as: 'professional'
            }
          },{
            $lookup:
            {
              from:'availabilities',
              localField: 'availability',
              foreignField: '_id',
              as: 'availability'
            }
          },{
            $unwind: '$availability'
          },{
            $match:{$and:[{"availability.start":{$lte:new Date(req.query.dateFrom)}},{"availability.end":{$gte:new Date(req.query.dateTo)}}]}
          },{
            $lookup:
            {
              from:'locations',
              localField: 'location',
              foreignField: '_id',
              as: 'location'
            }
          },{
            $project:{
              "_id":1,
              "email":"$user.email",
              "organization_name":"$user.organization_name",
              "website":"$user.website",
              "profile_pic_hash":"$user.profile_pic_hash",
              "bio_hash":"$user.bio_hash",
              "venue_type":"$venue.venue_type",
              "capacity":"$venue.capacity",
              "flat_fee":"$professional.flat_fee",
              "per_participant_fee":"$professional.per_participant_fee",
              "hourly_fee":"$professional.hourly_fee",
              "start_date":"$availability.start",
              "end_date":"$availability.end",
              "distance":"$dist.calculated",
              "location":"$location.location.coordinates",
              "country":"$location.country",
              "city":"$location.city",
              "street":"$location.street",
              "number":"$location.number",
              "zip":"$location.zip"}}
    

    それは私にとって完璧に機能しました。ありがとう Anthony Winzlet あなたの助けに。




    1. node、expressjsのelasticsearchでマングースからインデックスを作成する方法

    2. PHPとMongoがVagrantで、キャッチされない例外「MongoException」とメッセージ「BSONドキュメントのサイズはxバイト、最大は0」

    3. MongoDbのグローバル自動インクリメントフィールド

    4. mongodbでフィールドをインクリメントする方法は?