我正在尝试使用nativescript-couchbase-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,
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]});
这些情况不起作用。他们都不是。唯一有效的是第一个带有type_id
的所以问题是-如何使用where数组查询相应的数据?
数据样本:
{
"type_id": 2,
"title": "some name",
"regionId": 372,
"uid": 16177,
"filters": [
1,
2,
3
]
},
P.S。原始存储库中有一个issue。但它根本没有任何活动。
我必须同意插件文档会更好。但是,如果您经过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);