janez89 / mongoose-materialized

mongoose materialized plugin
59 stars 22 forks source link

getChildrenTree returns wrong tree with sort option #26

Open daaru00 opened 8 years ago

daaru00 commented 8 years ago

I have some problem to fetch children of node, my data is:

{
  "_id": "56fbcfde91c3eca907b561b0",
  "path": "56fbcfde91c3eca907b561b0",
  "name": "root"
}
{
  "_id": "56fbd401947323790b06c02b",
  "path": "56fbcfde91c3eca907b561b0#56fbd401947323790b06c02b",
  "name": "1",
  "parent": "56fbcfde91c3eca907b561b0"
}
{
  "_id": "56fbd405947323790b06c02c",
  "path": "56fbcfde91c3eca907b561b0#56fbd401947323790b06c02b#56fbd405947323790b06c02c",
  "name": "2",
  "parent": "56fbd401947323790b06c02b"
}
{
  "_id": "56fbd408947323790b06c02d",
  "path": "56fbcfde91c3eca907b561b0#56fbd40c947323790b06c02e#56fbd408947323790b06c02d",
  "name": "3",
  "parent": "56fbd40c947323790b06c02e"
}
{
  "_id": "56fbd40c947323790b06c02e",
  "path": "56fbcfde91c3eca907b561b0#56fbd40c947323790b06c02e",
  "name": "4",
  "parent": "56fbcfde91c3eca907b561b0"
}

The tree should be: root -1 --2 -4 --3 the path property is correctly set: 3 path is 56fbcfde91c3eca907b561b0#56fbd40c947323790b06c02e#56fbd408947323790b06c02d translatable into root 4 3. When I use rootcat.getChildrenTree({options:{sort:'order'}}, callback); the result is: 1 --2 --3 4 but if I don't use the order strategy rootcat.getChildrenTree(callback); the result is right!

I using mongoose v4.4.10, nodejs v0.10.25 and mongodb v3.2.1