SamVerschueren / dynongo

MongoDB like syntax for DynamoDB
MIT License
58 stars 16 forks source link

insert with subdocument #42

Closed mikedizon closed 8 years ago

mikedizon commented 8 years ago

Getting unknown operator varName when trying to insert a JSON object with nested documents. Is this not supported?

SamVerschueren commented 8 years ago

It is supported. Can you show me a small example that's not working for you?

mikedizon commented 8 years ago

http://dpaste.com/074RGWY

SamVerschueren commented 8 years ago

It might be not clear from the docs, I should really work on that (PRs are always welcome :)), but insert expects 2 arguments. The first object being the primary index + optional global secondary index. The second argument being the rest of the document. So in your case, I think it should be something like this:

Could you try this one?

product.insert(
    {
        id: '6dc798c4d9dcd4cb72b3e590b2287a9b98f12c9b'
    },
    {
        foo: {
            id: '123', 
            email: 'abc@example.com'
        },
        shippingAddress: {
            shipping_address_city: 'New York City',
            shipping_address_country: 'United States',
            shipping_address_country_code: 'US',
            shipping_address_line1: '123 Fake St',
            shipping_address_state: 'NY',
            shipping_address_zip: '10005',
            shipping_name: 'Name'
        }
    }
).exec().then(
  reference => {
     console.log('reference', reference)
})
mikedizon commented 8 years ago

Getting SyntaxError: missing ) after argument list

SamVerschueren commented 8 years ago

Can you take a screenshot of the error or copy paste it here in GitHub? This could provide me with useful information.

mikedizon commented 8 years ago

Here you go

http://dpaste.com/1QFMSSR

SamVerschueren commented 8 years ago

This is not a dynongo issue. Aren't you using a file to write that code?

Save as index.js

'use strict';
const db = require('dynongo');

db.connect({
    accessKeyId: 'accessKeyId',
    secretAccessKey: 'secretAccessKey',
    region: 'us-west-1'
});

// In case `Product` is your table name
const product = db.table('Product');

// Add your product.insert code here

Make sure to npm install dynongo first and then run

$ node index.js

mikedizon commented 8 years ago

Just ran that, nothing printed. I'm currently debugging in the terminal if that makes any difference.

mikedizon commented 8 years ago

oh wow, that worked. can I not use this in a terminal session?

SamVerschueren commented 8 years ago

I don't think you can require packages right? If it is possible, then just make sure you did everything like I showed. If not, then no :).