当前位置: 首页 > 知识库问答 >
问题:

Cloud firestore“!='查询

姚宪
2023-03-14

根据firestore文档,我可以通过组合'>'和'<'查询来执行相当于‘!='的查询:

但我到底该怎么做呢?如果可能,请提供精确示例的代码(查询结果!=30)。

共有1个答案

戚勇
2023-03-14
var query = citiesRef.where("population", ">", 860000).where("population", "<", 860000);

我认为您引用的文档摘录意味着您必须声明两个查询(见下文),并在代码中合并这两个查询的结果。

var query1 = citiesRef.where("population", ">", 860000);
var query2 = citiesRef.where("population", "<", 860000);

var query1 = yourRef.where("age", ">", "30");
var query2 = yourRef.where("age", "<", "30");

下面是一段代码,用于文档中的cities示例。依次打开这两个HTML页面。第一个将创建一些城市记录。第二个将在一个数组中连接两个查询的结果,并将其打印在控制台中。

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>2</title>

    <script src="https://www.gstatic.com/firebasejs/5.3.1/firebase-app.js"></script>
   <script src="https://www.gstatic.com/firebasejs/5.3.1/firebase-firestore.js"></script>
</head>

<body>
    <script>
        // Initialize Firebase
        var config = {
            apiKey: ".....",
            authDomain: ".....",
            databaseURL: ".....",
            projectId: "....."
        };

        firebase.initializeApp(config);

        var db = firebase.firestore();
        var citiesRef = db.collection('cities');

    citiesRef.doc("SF").set({
     name: "San Francisco", state: "CA", country: "USA",
     capital: false, population: 860000,
     regions: ["west_coast", "norcal"] });
    citiesRef.doc("LA").set({
     name: "Los Angeles", state: "CA", country: "USA",
     capital: false, population: 3900000,
     regions: ["west_coast", "socal"] });
    citiesRef.doc("DC").set({
     name: "Washington, D.C.", state: null, country: "USA",
     capital: true, population: 680000,
     regions: ["east_coast"] });
    citiesRef.doc("TOK").set({
     name: "Tokyo", state: null, country: "Japan",
     capital: true, population: 9000000,
     regions: ["kanto", "honshu"] });
   citiesRef.doc("BJ").set({
     name: "Beijing", state: null, country: "China",
     capital: true, population: 21500000,
     regions: ["jingjinji", "hebei"] });

    </script>

</body>

</html>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>2</title>

    <script src="https://www.gstatic.com/firebasejs/5.3.1/firebase-app.js"></script>
   <script src="https://www.gstatic.com/firebasejs/5.3.1/firebase-firestore.js"></script>
</head>

<body>
    <script>
        // Initialize Firebase
        var config = {
            apiKey: ".....",
            authDomain: ".....",
            databaseURL: ".....",
            projectId: "....."
        };

        firebase.initializeApp(config);

        var db = firebase.firestore();
        var citiesRef = db.collection('cities');

        var query1 = citiesRef.where("population", ">", 860000);
        var query2 = citiesRef.where("population", "<", 860000);

        var fullArray = [];    

        query1.get()
            .then(function (querySnapshot) {
                console.log(querySnapshot.docs);
                (querySnapshot.docs).forEach((element, index, array) => {
                    console.log(element.data().population);
                });
                fullArray = fullArray.concat(querySnapshot.docs);
                return query2.get();
            })
            .then(function (querySnapshot) {
                console.log(querySnapshot.docs);
                (querySnapshot.docs).forEach((element, index, array) => {
                    console.log(element.data().population);
                });
                fullArray = fullArray.concat(querySnapshot.docs);
                console.log('Final resulting array:');
                fullArray.forEach((element, index, array) => {
                    console.log(element.data().population);
                });
            })
            .catch(function (error) {
                console.log("Error getting documents: ", error);
            });

    </script>
</body>
</html>
 类似资料:
  • 我刚开始在DynamoDB上建一个社交网站。 我将有相当数量的数据与一个用户相关,我计划将这些全部放入一个表中--例如: 用户ID 出生日期 头发 照片URL 详细信息 可能有几百个属性。 问题: 将这么多数据放入一个表中有什么问题吗? 我如何查询该数据(我是否可以执行类似这样的查询:“所有在这个年龄,这个颜色头发,这个位置,并且这次登录的成员)-假设所有这些数据都包含在表中? 如果一个表的内容很

  • 以下策略可用于仓库基础结构来解决查询。你可以在XML配置中的命名空间通过query-lookup-strategy属性来配置策略或者在JAVA配置中通过Enable${store}Repositories声明queryLookupStrategy属性。有些策略可能对于特别的datastores并不支持。 CREATE 从查询方法名来尝试构建一个特别的数据查询。一般的方法都是从方法名称中移除已知设定

  • 问题内容: 我正在尝试使用Elasticsearch获得完全匹配的结果(所以我不在乎在这里得分) 我看到有两种方法可以做到这一点: 要么 两者都能工作,并给我想要的结果。它们之间有什么区别?使用一个与另一个相比有性能优势吗? (我正在使用Elasticsearch V 5.6) 谢谢 ! 问题答案: 恒定分数查询可为任何匹配的文档提供相等的分数,而与诸如等等的任何评分因素无关。当您不关心文档是否匹

  • Graphql 为查询而生,所以我们首先试试它的查询功能吧. 准备工作 克隆库: git clone https://github.com/zhouyuexie/learn-graphql 安装依赖: cd learn-graphql && npm install 运行: npm start 现在打开你的浏览器输入http://localhost:12580/graphql,或者点击这里. Gra

  • 说明 微信支付-订单附加信息查询接口SDK。 官方文档:https://pay.weixin.qq.com/wiki/doc/api/external/declarecustom.php?chapter=18_2 类 请求参数类 请求参数 类名:\Yurun\PaySDK\Weixin\CustomDeclareQuery\Request 属性 名称 类型 说明 $_apiMethod strin

  • 说明 支付宝报关查询 官方文档:https://docs.open.alipay.com/155/104780/ 类 请求参数类 请求参数 类名:\Yurun\PaySDK\AlipayCrossBorder\Customs\Submit\Request 属性 名称 类型 说明 $service string 接口名称 $out_request_no string 报关请求号 需要查询的商户端报关

  • 说明 支付宝境外在线支付-查询 官方文档:https://global.alipay.com/service/website_split_cn/13 类 请求参数类 请求参数 类名:\Yurun\PaySDK\AlipayCrossBorder\Online\Query\Request 属性 名称 类型 说明 $service string 接口名称 $trade_no string 支付宝根据商

  • 模型查询和数据库查询方法的区别主要在于,模型中的查询的数据在获取的时候会经过获取器的处理,以及更加对象化的获取方式。 模型查询除了使用自身的查询方法外,一样可以使用数据库的查询构造器,返回的都是模型对象实例。但如果直接调用查询对象的方法,IDE可能无法完成自动提示。 获取单个数据 获取单个数据的方法包括: // 取出主键为1的数据 $user = User::get(1); echo $user-