代码之家  ›  专栏  ›  技术社区  ›  Vikram Shinde

GCP数据存储(NDB)中的循环

  •  0
  • Vikram Shinde  · 技术社区  · 8 年前

    如何循环访问GCP数据存储中的实体?

    我们希望循环数据存储中的每个用户,并根据其状态进行更新。

    2 回复  |  直到 8 年前
        1
  •  2
  •   Akash    8 年前

    使用数据存储查询来实现这一点。

    Link to Documentation

        2
  •  0
  •   Richard Rebeco    8 年前

    如果您使用的是node js,请尝试以下方法:

        datastore.runQuery(query, (err,entities) => {
            var searches = [];
            if(typeof entities !== 'undefined' && entities.length > 0) {
                var keys = entities.map(function(entity) {
                    searches.push(entity);
                });
    
                //Setting the response object
                response.status="OK";
                response.message="";
                response.data={ 
                    "searches": searches
                };
            }else{
                response.status="OK";
                response.message="Empty result";
            }
    
            //Returning the response to client
            res.status(200).send(JSON.stringify(response));
        });