Query

Query

find

Parameters:

  • [conditions] «Object» must use hashkey and/or sortkey

Returns:

  • «Object»

Finds documents using the DynamoDB query method.

Examples:

// find people named john and at least 18
let johns = await People.find( { name: 'john'})
    .filter('age')
    .gte(18)
    .exec();

// find the first 3 people named john
let johns = await People.find({ name: 'john' }).limit(3).exec();

findOne

Parameters:

  • [conditions] «Object» must use hashkey and/or sortkey

Returns:

  • «Object»

Finds one document using the DynamoDB query method.

Examples:

// find one location
let location = await Locations.findOne({ id: 'abcd123' }).exec();

scan

Parameters:

  • [conditions] «Object»

Returns:

  • «Object»

Finds documents using the DynamoDB scan method.

Examples:

// find people aged 18 and named 'john'
let johns = await People.scan( { age: 18 } )
    .filter('name')
    .eq('john')
    .exec();

// find the first 3 people named john
let johns = await People.scan({ name: 'john' }).limit(3).exec();

save

Parameters:

  • [document] «Object»

Returns:

  • «Undefined»

Saves document using the DynamoDB put method.

Examples:

// save a new Dog document
await Dog.save({
    ownerId: 4,
    name: 'Odie',
    breed: 'Beagle',
    color: ['Tan'],
    cartoon: true
});

findOneAndUpdate

Parameters:

  • [conditions] «Object» must use hashkey and/or sortkey.
  • [update] «Object»

Returns:

  • «Object»

Finds one document using the DynamoDB query method and then will update that document using the DynamoDB update method.

Examples:

// find person named john and rename to andrew
let johns = await People.findOneAndUpdate( { name: 'john'}, {
    name: 'andrew'
} ).exec();

findOneAndDelete

Parameters:

  • [conditions] «Object» must use hashkey and/or sortkey.

Returns:

  • «Object»

Finds one document using the DynamoDB query method and then will update that document using the DynamoDB delete method.

Examples:

// find person named john and delete
let johns = await People.findOneAndDelete({ name: 'john'}).exec();