过滤Array中匹配的位置

时间:2016-10-12 14:07:49

标签: c# mongodb mongodb-query

当我修改我的过滤器时,只选择ArtistDocument artist_IDartistIds数组中包含匹配项的// array. string[] artistsIds = new string[] { "123ABC", "456XYZ" }; // filter. var filter = Builders<ArtistsDocument>.Filter.Where(p => p.artist_ID.Any(b => artistsIds.Contains(b.ToString()))); filter = filter & Builders<ArtistsDocument>.Filter.Eq("genre", "Rock"); filter = filter & Builders<ArtistsDocument>.Filter.Lt(x => x.transactionDate, DateTime.Now.AddSeconds(Math.Abs(30) * (-1))); // update. var update = Builders<ArtistsDocument>.Update.Set("status", "Processing"); // options. var options = new FindOneAndUpdateOptions<ArtistsDocument> { Sort = Builders<ArtistsDocument>.Sort.Ascending(x => x.fileName).Ascending(x => x.priority), ReturnDocument = ReturnDocument.After }; // document. var doc = await artistsCollection.FindOneAndUpdateAsync(filter, update, options); ,我收到以下错误。

  

“不支持表达式树:{document} {artist_ID}”System.Exception {System.NotSupportedException}

 <li>
         <div class="promo-image">             
                <img src="some source">           
         </div>

         <div class="promo-wrapper ">
           <div class="promo-block">
             <h3 class="title">blah</h3>
                <div class="module-copy">
                     <h6>more blah</h6>
                </div>
                <a class="cta" target="" title="blah" href="/relative-landing-Url">Explore</a>
           </div>
         </div>

         <a target="" title="Explore" href="relative-landing-url" class="carousel-wrap-link"></a>  

</li> 

1 个答案:

答案 0 :(得分:1)

我相信你可以用ElemMatch实现你想要的东西

var elemMatchFilter = Builders<YourModel>
    .Filter
    .ElemMatch(x => x.YourArray, x => x.ArrayField1 == field1 && x.x.ArrayField2 == field2);

类似的东西:

.state('serialCreateCase', {
  url: '^/sn={id}',
  params: {
    id: {}
  },
  templateUrl:'abxy.html',
  controller: 'controllersss as ctrl',
}