【发布时间】:2019-11-11 12:57:57
【问题描述】:
我关注this页面寻找更好的基于时间戳的查询方式
我使用 Cosmonaut 库,这是 cosmos DB 设置
var cosmosSettings = new CosmosStoreSettings(cosmosDbName, endpointUrl, key, settings: setting =>
{
setting.IndexingPolicy = new IndexingPolicy(
new RangeIndex(DataType.String, precision: -1),
new RangeIndex(DataType.Number, precision: -1));
});
然后我尝试根据日期时间查询如下
public async Task<IEnumerable<collectionNameObject>> GetAsync(GetCollection query)
{
var result = await _objectStore
.Query(new FeedOptions {PartitionKey = new PartitionKey(query.x)})
.Where(r =>
r.y == query.y
&& r.z == query.z
&& r.Timestamp.Date >= query.Date.Date)
.ToListAsync();
return result;
}
这是我在 CosmosDb 中保存的内容
[CosmosCollection("collectionNameObject")]
public class collectionNameObject: Entity
{
[CosmosPartitionKey]
[JsonProperty("x")]
public string x{ get; set; }
[JsonProperty("z")] public string z{ get; set; }
[JsonProperty("y")] public string y{ get; set; }
[JsonProperty("timestamp")] public DateTime Timestamp { get; set; }
}
问题是查询结果总是空的,但是,如果我删除时间戳过滤器,我会得到我所期望的。不清楚我错过了什么,所以我想知道是否有人有更好的建议或提示?
【问题讨论】:
标签: c# azure-cosmosdb