Jugglingdb with mongodb; schema; array of strings

540 views
Skip to first unread message

Sebastian Woinar

unread,
Feb 7, 2013, 10:18:19 AM2/7/13
to compo...@googlegroups.com
Hey,
I'm confronted with one tiny problem:
I cannot create a schema with an array of strings for mongodb

For example
post = {
   title: "Hello World",
	tags: [ "important", "classic"]
}

Is this a feature instead of a bug?? Is this because they want to have a cross-platform ORM and for example mysql would not allow that easily?
Or did I just not see an elegant way to implement that?
Has anyone a best practice pattern, how to use arrays as properties with jugglingdb?
Thanks, guys!
  Sebastian

Anatoliy Chakkaev

unread,
Feb 7, 2013, 1:36:40 PM2/7/13
to compo...@googlegroups.com
Hey Sebastian,

I think it adapter dependent issue, because in my redis-hq adapter I can use any objects, strings, arrays as value of object property. I'm not sure about mongodb, but there's no restrictions from the jugglingdb side, any problems you may have comes from adapter.

Cheers, Anatoliy


--
The official community of CompoundJS.
 
website: compoundjs.com
source: https://github.com/1602/compound
bug reports: https://github.com/1602/compound/issues?state=open
---
You received this message because you are subscribed to the Google Groups "CompoundJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to compoundjs+...@googlegroups.com.
To post to this group, send email to compo...@googlegroups.com.
Visit this group at http://groups.google.com/group/compoundjs?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Sebastian Woinar

unread,
Feb 8, 2013, 7:18:21 AM2/8/13
to compo...@googlegroups.com
Dear all who want to use arrays as well,
Anatoliy, thanks for your advice.

I changed my code to
var Post = describe('Post', function () {
    property('keywords', String, {default: new Array()});
    property('content', String);
    ….
});

So I declare my property as a string, but put an array of strings into it. That works - even if it isn't that nice.

Thanks again!

Have a good weekend, everybody.

Cheers, Seb.

Ark R

unread,
Feb 21, 2013, 7:28:04 PM2/21/13
to compo...@googlegroups.com, seba...@woinar.de
So I'm attempting to do what your doing with the array of strings, however, when I send it back to the client it looks like this:

"tags": "[\"1.9.10\",\"word!\"]"

Any suggestions on where to fix this? Juggling db? some kind of hook somewhere?

Thanks.

Anatoliy Chakkaev

unread,
Feb 22, 2013, 7:41:40 AM2/22/13
to compo...@googlegroups.com
declare property as JSON type:

schema.define('Model', {propertyName: Schema.JSON});

Ark R

unread,
Feb 22, 2013, 11:38:20 AM2/22/13
to compo...@googlegroups.com, ma...@anatoliy.in
I attempted to use 

property('tags', { type: JSON });

in my schema.js

and it still comes back with the quotes escaped.

Deepak Sharma

unread,
Dec 24, 2016, 9:39:10 AM12/24/16
to CompoundJS, seba...@woinar.de
Hello,

I know this is a really old post, but I faced a similar issue while using JugglingDB. So, this is for those who reach here in search of a solution:

    const schemaTemplate = {
        title: String,
        tags: Array(String),
    };

Using the type as Array of Strings allows me to get this structure as output when I try to fetch a record:

    {
        title: 'sample post',
        tags:[[String: 'tech'], [String: 'nodejs']]
    };

Now, you can easily iterate over the tags:
    
    post.tags.items.forEach(function(tag) {
        doSomethingAwesome(tag.toString());
    });

You can notice, I used items to get all tags from tags List object, and since, the tags obtained are List Item objects, you'd need to convert them to string.
Reply all
Reply to author
Forward
0 new messages