MongoDB中的过滤器不起作用

时间:2018-08-03 05:28:30

标签: c# mongodb

我正在尝试使用mongoDb中的正则表达式模式过滤数据,并按降序对其进行排序。

var filter = Builders<TDocument>.Filter.Regex(Property, new BsonRegularExpression("/^[0-9 - _ ! @ # $ % ^ & * (`~)?/+<|>.{}]/"));

var SortBy = Builders<TDocument>.Sort.Descending(_ => _.Contact.Accounts.Name);

var Data= await db.GetCollection<TDocument>().Find(filter).Sort(SortBy).Limit(10).Skip(20)).ToListAsync();

数据返回零。即使我的收藏中包含与该过滤器匹配的数据。文件总数为2.4k。

我使用以下代码创建了索引:

  var indexUniqueIdDesc = Builders<TDocument>.IndexKeys.Descending(Property);
  await db.GetCollection<TDocument>(collection).Indexes.CreateOneAsync(indexUniqueIdDesc, new CreateIndexOptions<TDocument>{ Background = true, Sparse = true });

我不是要获取数据吗,因为这是创建索引的问题,还是由于数据量很大,还是我写错了查询?

0 个答案:

没有答案