nativescript couchbase插件查询
我正试着用它。 这是我的密码:nativescript couchbase插件查询,nativescript,couchbase,couchbase-lite,nativescript-plugin,Nativescript,Couchbase,Couchbase Lite,Nativescript Plugin,我正试着用它。 这是我的密码: whereArray.push({ property: "type_id", comparison: "equalTo", value: typeId }); return itemsDb.query({ select: [], where: whereArray, order: [{property: "rating", direction: "desc"}], limit: this.PAGE_SIZE, of
whereArray.push({ property: "type_id", comparison: "equalTo", value: typeId });
return itemsDb.query({
select: [],
where: whereArray,
order: [{property: "rating", direction: "desc"}],
limit: this.PAGE_SIZE,
offset: page * this.PAGE_SIZE
});
一切正常:where子句中的条件、顺序、限制和偏移。
但我想给我的情况增加一些新的东西,我正在尝试这样做:
whereArray.push({ property: "title", comparison: "like", value: "some name"});
or
whereArray.push({ property: "filters", comparison: "in", value: [1,2,3]});
这些案子不管用。他们两个都不是。唯一有效的是第一个id类型为的
所以问题是-如何使用where数组查询相应的数据
数据样本:
{
"type_id": 2,
"title": "some name",
"regionId": 372,
"uid": 16177,
"filters": [
1,
2,
3
]
},
另外,在原始存储库中有一个。但是它没有任何活动。我必须同意插件文档可能会更好。但是,如果您仔细查看TypeScript声明,就会发现代码中存在问题 添加多个where条件时,必须包含逻辑运算符
import {
Couchbase,
QueryLogicalOperator,
QueryComparisonOperator
} from "nativescript-couchbase-plugin";
const database = new Couchbase("my-database");
// Insert docs for testing
const documentId = database.createDocument({
type_id: 2,
title: "some name",
regionId: 372,
uid: 16177,
filters: [1, 2, 3]
});
console.log(documentId);
// Query
const results = database.query({
select: [],
where: [
{
property: "type_id",
comparison: "equalTo",
value: 2,
logical: QueryLogicalOperator.AND
},
{
property: "filters",
comparison: "in",
value: [1, 2, 3]
}
],
order: [{ property: "rating", direction: "desc" }],
limit: 10
});
console.log(results);
你也可以发布一些示例数据/文档来帮助我们更好地理解查询吗?我已经用一些示例数据更新了帖子。我已经添加了它。我解决了逻辑运算符的问题,但没有解决子查询的问题:我只想在具有字段过滤器[1,2,3]的文档中搜索[1]。此外,我还没有找到一种通过这个插件使用模糊搜索的方法。我试过有*和没有*的“喜欢”操作符。我不确定我是否理解你的意思。添加逻辑运算符后,OP中的查询将正常工作。在Couchbase中搜索子查询如何?注意:逻辑运算符必须处于第二个条件!(至少对我来说,只有在Nativescript vue-Android上才是这样)