Wednesday, 24 May 2017

DynamoDB results not equal to object modeling

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.



via Mohamed Nizar

No comments:

Post a Comment