gstore-node
v7.x
v7.x
  • Introduction
  • Getting Started
    • Motivation
    • Installation
    • Create a gstore instance
  • Schema
    • About
    • Type validation
    • Value validation
    • Additional properties settings
    • Schema options
    • Joi Schema
    • Methods
      • path()
      • virtual()
    • Custom methods
  • Model
    • Creation
    • Methods
      • GET
      • UPDATE
      • DELETE
      • excludeFromIndexes()
      • key()
      • sanitize()
      • clearCache()
  • Entity
    • Creation
    • Properties
    • Methods
      • SAVE
      • plain()
      • populate()
      • model()
      • datastoreEntity()
      • validate()
  • Queries
    • @google-cloud Query
    • list()
    • findOne()
    • deleteAll()
    • findAround()
  • Populate
  • Middleware (hooks)
    • About
    • Pre hooks
    • Post hooks
  • Cache / Dataloader
    • Dataloader
    • Cache
  • gstore Methods
    • save()
  • Typescript
  • Appendix
    • Error Codes
    • Credits
Powered by GitBook
On this page

Was this helpful?

  1. Queries

findAround()

Find entities before or after an entity based on a property and a value.

MyModel.findAround(
    /* {string}. -- The property to look around */
    <property>,
    /* {string} -- The property value */
    <value>,
    /* {object} -- { before|after: Number [, ... ] } */
    <options>
)

The options argument is an object that must contain either a "before" or an "after" property setting the limit of entities to retrieve.

Examples:

// Find the next 20 post after march 1st
BlogPost.findAround('publishedOn', '2016-03-01', { after: 20 })
        .then((entities) => {
            ...
        });

// Find 10 users with the lastname coming before 'Jagger'
User.findAround('lastname', 'Jagger', { before: 10 })
    .then( ... );

Additional options

  • readAll {boolean} true | false If set to true and with format set to "JSON" (default) it will output all the entity properties regardless of the read parameter defined in the Schema.

  • format {string} "JSON" (default) | "ENTITY"

  • showKey(default: false) Adds a "__key" property to the entity data with the complete Key from the Datastore.

  • cache (default: the "global" cache configuration) "true" = read from the cache and prime the cache with the query response.

  • ttl (default: the global cache.ttl.queries value) Custom TTL value for the cache. For multi-store it can be an Object of TTL values.

const options = { after: 20, readAll: true, format: "ENTITY" };
BlogPost.findAround('publishedOn', '2016-03-01', options)
        .then((entities) => { ... });

// disable caching
const options = { after: 20, cache: false };
BlogPost.findAround('publishedOn', '2016-03-01', options).then(...);

// set TTL for this query
// ttl can also be an object for multi-store ---> { memory: 600, redis: 3600 }
const options = { after: 20, ttl: 600 };
BlogPost.findAround('publishedOn', '2016-03-01', options).then(...);
PreviousdeleteAll()NextPopulate

Last updated 6 years ago

Was this helpful?

consistency Specify either "strong" or "eventual". If not specified, default values are chosen by Datastore for the operation. Learn more about strong and eventual consistency .

here