2016-05-03 1 views
0

以下の集計クエリを使用して、一致するキーワードのリスト内のキーワード検索 "中国語"クローズド:集計クエリのIDのリストを返すには、私はmongodbを新しくしました

db.business.aggregate([ 
    { 
     $match:{ 
     $text:{ 
      $search:"chinese" 
     } 
     } 
    }, 
    { 
     $match:{ 
     "_id":{ 
      $in:[ 
       ObjectId("571453a82ece1392240f7b91"), 
       ObjectId("5714537b2ece1392240f7b8c"), 
       ObjectId("5714539a2ece1392240f7b8e"), 
       ObjectId("571453962ece1392240f7b8d") 
      ] 
     } 
     } 
    }, 

]) 

以下はmongodbのサンプルデータです。

{ 
    "_id" : ObjectId("571453b32ece1392240f7b93"), 
    "_class" : "com.halal.sa.data.entities.Business", 
    "name" : "Chillies", 
    "description" : "nice restaurant", 
    "cuisine" : [ 
     "veg-nonveg", 
     "chinese", 
     "kabab" 
    ], 
    "address" : { 
     "streetAddress" : "1000 bentley road", 
     "city" : "marietta", 
     "pincode" : 30067, 
     "landmark" : "near delk road", 
     "location" : { 
      "type" : "Point", 
      "coordinates" : [ 
       -84.4774305, 
       33.9202151 
      ] 
     } 
    }, 
    "phone" : 123, 
    "email" : "[email protected]", 
    "ownerEmail" : "[email protected]", 
    "status" : "2", 
    "website" : "test.com", 
    "authenticity" : "1" 
} 

コレクションからすべてのドキュメントを返す代わりに_idsのリストのみを返す正確な変更された集約クエリをお知らせください。事前のおかげで、私はそれだけでクエリで$プロジェクトを使用しました

答えて

0

は、

db.business.aggregate([ 
    { $match: { $text: { $search: "chinese" } } }, 
    { $match: { "_id": {$in : [ObjectId("571453a82ece1392240f7b91"), ObjectId("5714537b2ece1392240f7b8c"),ObjectId("5714539a2ece1392240f7b8e"),ObjectId("571453962ece1392240f7b8d")]} } },  
    {$project: {"_id": "$_id"}} 
]) 
:-)それのthats
関連する問題