Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Node.js的Google云数据存储查询_Node.js_Google App Engine_Google Cloud Datastore - Fatal编程技术网

使用Node.js的Google云数据存储查询

使用Node.js的Google云数据存储查询,node.js,google-app-engine,google-cloud-datastore,Node.js,Google App Engine,Google Cloud Datastore,有一种方法可以使用Node.js和Google云数据存储获取所有数据 var query = ContactModel.query();//contact model is a schema which instantiates gstore schema query.run().then((result) => { const response = result[0]; var entities = response.entities; callb

有一种方法可以使用Node.js和Google云数据存储获取所有数据

var query = ContactModel.query();//contact model is a schema which instantiates gstore schema

query.run().then((result) => {
    const response = result[0];
     var entities       = response.entities;
    callback('',entities);
});
var query = ContactModel.query()

query.filter(key, value)

query.run().then((result) => {
  const response = result[0],
        entities = response.entities

  callback('',entities)
})
有没有一种方法可以使用Node.js和Google云数据存储运行自定义查询或简单地说是过滤器。我只能找到一个使用Node.js和Google云数据存储的查询示例

var query = ContactModel.query();//contact model is a schema which instantiates gstore schema

query.run().then((result) => {
    const response = result[0];
     var entities       = response.entities;
    callback('',entities);
});
var query = ContactModel.query()

query.filter(key, value)

query.run().then((result) => {
  const response = result[0],
        entities = response.entities

  callback('',entities)
})
filter函数将根据键和值进行过滤,filter函数采用可选的第三个参数,第三个参数是等于、小于等条件。。但如果只提供两个参数,它将检查是否相等。还有其他函数,如limit、order、groupBy等。请查找文档。

我建议您使用,它有一个非常简单有效的API,并且有许多如何进行高级查询的示例

因为它详细说明了如何列出所有元素

// blog-post.model.js

// Create Schema
const blogPostSchema = new gstore.Schema({
    title : { type: 'string' },
    isDraft: { type: 'boolean' }
});

// List query settings
const listQuerySettings = {
    limit : 10,
    order : { property: 'title', descending: true }, // descending defaults to false and is optional
    select : 'title',
    ancestors : ['Parent', 123],  // will add an "hasAncestor" filter
    filters : ['isDraft', false] // operator defaults to "=",
};

// Add settings to schema
blogPostSchema.queries('list', listQuerySettings);

// Create Model
const BlogPost = gstore.model('BlogPost', blogPostSchema);