【问题标题】:DataStax Stargate Document APIDataStax Stargate 文档 API
【发布时间】:2021-07-14 04:50:57
【问题描述】:

DataStax Document API Swagger UI 中显示的 Swagger 文档中的 a JSON blob with search filters, allowed operators: $eq, $ne, $in, $nin, $gt, $lt, $gte, $lte, $exists 是什么意思,没有记录,所以我想问一下查询字符串是否基于 MongoDB?

【问题讨论】:

  • 我的意思是这些完全相同的运算符在 MongoDB 的查询语言中。

标签: mongodb cassandra datastax stargate-oss


【解决方案1】:

在 Cassandra 之上公开的 Document API 由开源项目 Stargate 提供,实际上是由 Datastax 开发并嵌入到他们的 Saas 解决方案 Astra 中。

您创建的 JSON 查询字符串在后台被解析并转换为适当的 CQL 查询。

源码不说谎你可以找到完整的代码here和专门解析where子句here

public List<FilterCondition> convertToFilterOps(
 List<PathSegment> prependedPath, 
 JsonNode filterJson) {
 
 List<FilterCondition> conditions = new ArrayList<>();

 if (!filterJson.isObject()) {
  throw new DocumentAPIRequestException("Search was expecting a JSON object as input.");
 }

 ObjectNode input = (ObjectNode) filterJson;
 Iterator<String> fields = input.fieldNames();
 while (fields.hasNext()) {
  String fieldName = fields.next();
  if (fieldName.isEmpty()) {
    throw new DocumentAPIRequestException(
        "The field(s) you are searching for can't be the empty string!");
  }
 ...

【讨论】:

    【解决方案2】:

    查询字符串在本质上与您在 Mongo 中找到的非常相似。

    这里有一些示例 where 子句给出一个想法:

    {"name": {"$eq": "Eric"}} - 很简单,匹配字段为 name 且值为 Eric 的文档

    {"a.age": {"$gt": 0}} - 您还可以引用文档中的嵌套字段

    {"friends.[0].name": {"$in": ["Cassandra"]}} - 数组元素使用[] 引用,如果文档的第一个朋友名为 Cassandra,这将匹配。

    {"friends.*.age": {"$gte": 24}} - 通配符* 可用于匹配数组中的任何元素,或特定嵌套级别的任何字段。这匹配任何年龄 >= 24 的朋友。

    【讨论】:

      猜你喜欢
      • 2021-11-12
      • 2021-11-15
      • 2021-11-16
      • 2014-01-27
      • 2021-11-29
      • 2019-04-03
      • 2015-10-11
      • 1970-01-01
      • 2013-01-14
      相关资源
      最近更新 更多