0

I have an object model like below.

'use strict';
var crypto = require('crypto');
var dynamoose = require('../../config/database');
var Schema = dynamoose.Schema; 
var NavSchema = new Schema({
    client_id: {
        type: String,
        hashKey: true
    },
    code: {
        type: String,
        rangeKey: 'client_id'
    },
    name: String,
    service_group: String,
    search_text : String,
    description : String,
    images : [],
    active : Boolean,
    price : Number,
    staff : [],
    time_period : Number,
    created_date : String,
    modified_date : String
});

 module.exports = dynamoose.model('Services', NavSchema);

I do a scan on my doc.It's returning the object by missing most of the attributes.See the query.

    exports.getServicesByGroup = function(req, res, next){
Services.scan('service_group').contains(req.body.group.code).where('client_id').eq(app.prepareUserClient(req)).exec(function(err, services) {
            if(err) res.json(err);
            var response = {
                data:services,
                errror:false
            }
            res.json(response);
        });

    }

Its returning this object. [ NewModel { client_id: 'abc', code: '001', name: 'Feathered Brows', service_group: '1', time_period: 2 }, NewModel { client_id: 'abc', code: '002', name: 'Anastasia Brows', service_group: '1' }] Most of the attributes are missing form the results.What is is the problem with my code.Please help. enter image description here Table view on dynamodb console.

enter image description here

Mohamed Nizar
  • 780
  • 9
  • 30
  • Do you have the missing attribute on table? Is the attribute name matching? Can you provide a screenshot? – notionquest May 25 '17 at 09:28
  • Yes, sure, Find the image https://drive.google.com/file/d/0ByY807SSQ6F9RkFSOFNSdElRNVk/view?usp=sharing , https://drive.google.com/file/d/0ByY807SSQ6F9c0RFWGFNbHdxTkE/view?usp=sharing – Mohamed Nizar May 25 '17 at 11:24
  • I can't access google drive. Please add as a image in OP. – notionquest May 25 '17 at 11:26
  • @notionquest, I have updated the post. – Mohamed Nizar May 25 '17 at 11:31
  • 1
    If the attributes are not present in the item, the output wouldn't have it. For example, the item 'abc' doesn't have search_text, so it is not present in the output which is as expected. The non-key attributes are not mandatory on all the item. You can expect only key attributes in the output. All other non-key attributes may or may not present – notionquest May 25 '17 at 11:41
  • But why those values are not even getting save on dynamoos ? – Mohamed Nizar May 25 '17 at 14:18
  • It depends on the save item data. DynamoDB doesn't enforce the non-key attributes to be mandatory. This is similar to NULLABLE fields on RDBMS. – notionquest May 25 '17 at 14:20

0 Answers0