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

loop in GCP datastore (NDB)

如何循环遍历 GCP 数据存储区中的实体?

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

Use Datastore Queries to achieve this.

Link to Documentation

如果您使用的是 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));
    });