I use Sails.js (0.9.8) and MongoDB (via the sails-mongo adapter) to create a set of pages that can be arranged in a tree view. I would like to save the page path in a UUID array
My model:
module.exports = { schema: true, attributes: { uuid: { type: 'string', unique: true, required: true, uuidv4: true }, name: { type: 'string', required: true, empty: false }, path: { type: 'array', required: true, array: true } } }
This works well when I save the root page (the path property has only one element because it is the root page. This is what it saved in MongoDB:
{ _id: ObjectId("52f853e9609fb6c0341bdfcc"), createdAt: ISODate("2014-02-10T04:22:01.828Z"), name: "Home Page", path: [ "a2b23e1f-954b-49a3-91f1-4d62d209a093" ], updatedAt: ISODate("2014-02-10T04:22:01.833Z"), uuid: "a2b23e1f-954b-49a3-91f1-4d62d209a093" }
But when I want to create a โsubpageโ below my previous created page (Home / Products), I get this error:
MongoError: E11000 Duplicate Key Error Index: cms-project.item. $ path_1 dup key: {: "a2b23e1f-954b-49a3-91f1-4d62d209a093"}
Here are the data I sent:
{ name: 'Products', uuid: 'a004ee54-7e42-49bf-976c-9bb93c118038', path: [ 'a2b23e1f-954b-49a3-91f1-4d62d209a093', 'a004ee54-7e42-49bf-976c-9bb93c118038' ] }
I probably missed something, but I donโt know what. If I store the path in a string instead of an array, it works fine, but I find it much less elegant and convenient.