0

I have the following Schemas in Mongoose/Node.js:

var ItemsSchema = new Schema({
    itemname: String,
    quantity: String
});

var ListSchema = new Schema({
    listname: String,
    items: [ItemsSchema]
});

var UsersSchema = new Schema ({    
    username: String,
    owned: [ListSchema]
});

So each User may have many Lists. And each list can contain many items. How can i insert new item to a specific list? Using User.findOne({"owned._id" : listid} ... will give me the user that own the specific list but i can't figure it out how to proceed to get the single list.

Thanks in advice!

1 Answer 1

1

you can try to do this.

User.findById(id, function(err, doc){
     doc.owned[n].items.push(item);
}

Any user has an independent list, you must access to a userlist and push an item to a specific list.

The users don't share the list, of course the items neither with this structure.

Sorry about my english.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you! It worked! My background is in the relation databases and switching to nosql need some change in perspective :)
;) Good luck! Perhaps help you this mongodb.org/display/DOCS/Admin+UIs I use MongoHub for mac, it's great!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.