janez89 / mongoose-materialized

mongoose materialized plugin
59 stars 22 forks source link

GetArrayTree field selection hides children #24

Open burakkilic opened 8 years ago

burakkilic commented 8 years ago

Hello;

I want to use this query in getArrayTree.

var query = {
    condition: {
    },
    fields: {
        _id: 1,
        name: 1,
        description: 1,
        price: 1,
        type: 1,
        image: 1,
        published: 1,
        children: 1
    },
    // sorting
    sort: {
        order: 1
    }
};

but children is not coming. Where am I wrong?

janez89 commented 8 years ago

Hello, the array tree method has 2 versions. small caps version work on document instance.

Get root document and use you can use the doc.getArrayTree(...);

Or YourCollection.GetArrayTree('MongoId', ...);

I'm work on the new version this module with new API.

burakkilic commented 8 years ago

I used document instance version:

doc.getArrayTree(query, function(err, tree) {
        if (err) res.json(err);
        return res.json({
            type: true,
            data: tree
        });
    });

and children is not sent.

When are you planning to release the new version by the way?

ectan commented 7 years ago

I found getArrayTree will return children if you include parentId in your query.fields.