xyb*_*rek 1 mongodb cassandra datastax
a JSON blob with search filters, allowed operators: $eq, $ne, $in, $nin, $gt, $lt, $gte, $lte, $exists在 DataStax Document API Swagger UI 中显示的 Swagger 文档中有什么内容,它没有记录在案,所以我想问一下查询字符串是否基于 MongoDB?
在 Cassandra 上公开的 Document API 由开源项目Stargate 提供,实际上由 Datastax 开发并嵌入到他们的 Saas 解决方案Astra 中。
与您创建的 JSON 查询字符串相比,将在适当的 CQL 查询中解析和转换。
源代码,不在于你可以找到完整的代码在这里和专门的where子句的解析这里
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!");
}
...
Run Code Online (Sandbox Code Playgroud)
小智 5
查询字符串在本质上与您在 Mongo 中找到的内容非常相似。
以下是一些示例 where 子句以供参考:
{"name": {"$eq": "Eric"}}- 足够简单,匹配name具有值字段的文档Eric
{"a.age": {"$gt": 0}} - 您还可以引用文档中的嵌套字段
{"friends.[0].name": {"$in": ["Cassandra"]}}- 使用 引用数组元素[],如果文档的第一个朋友名为 Cassandra,这将匹配。
{"friends.*.age": {"$gte": 24}}- 通配符*可用于匹配数组中的任何元素,或特定嵌套级别的任何字段。这匹配任何年龄 >= 24 的朋友。