jugglingdb icon indicating copy to clipboard operation
jugglingdb copied to clipboard

Can I nest objects?

Open cheapsteak opened this issue 12 years ago • 2 comments
trafficstars

I'm looking at a node/express/mongoose tutorial where you could do this


var Images = new Schema({
    kind: { 
        type: String, 
        enum: ['thumbnail', 'catalog', 'detail', 'zoom'],
        required: true
    },
    url: { type: String, required: true }
});

var Product = new Schema({
    title: { type: String, required: true },
    images: [Images],
});

Is there a way to do something similar with jugglingdb?

cheapsteak avatar Apr 01 '13 06:04 cheapsteak

Re: enum: ['thumbnail', 'catalog', 'detail', 'zoom'],

It could be handled on adapter level, i mean sql/mongodb adapters with specific implementation on data definition. But it you need enum for validation this is bad idea to list it in schema, use validations instead.

Re: images: [Images]

Yes, we are close to this. And again - it's adapter specific, but in jugglingdb we have a List class, which allows to use [] as type (untyped for now), it serialized as json now (I need it for redis and mysql), for mongodb it could be used as nested document, but IMO nested documents in mongo isn't really good practice (in common sense), i might be wrong, feel free to suggest implementation notes in that case.

On Mon, Apr 1, 2013 at 10:51 AM, cheapsteak [email protected]:

I'm looking at a node/express/mongoose tutorialhttps://gist.github.com/pixelhandler/1791080where you could do this

var Images = new Schema({ kind: { type: String, enum: ['thumbnail', 'catalog', 'detail', 'zoom'], required: true }, url: { type: String, required: true }}); var Product = new Schema({ title: { type: String, required: true }, images: [Images],});

Is there a way to do something similar with jugglingdb?

— Reply to this email directly or view it on GitHubhttps://github.com/1602/jugglingdb/issues/251 .

anatoliychakkaev avatar Apr 07 '13 15:04 anatoliychakkaev

@anatoliychakkaev

but IMO nested documents in mongo isn't really good practice (in common sense)

That's actually THE Mongo way. I personally prefer ArangoDB

iyobo avatar Oct 22 '16 14:10 iyobo