Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define a generic nested object in Mongoose

I would like to have a nested object in the detail for the activiy log. See the example. How do I define the schema in mongoose?

activity: {
    date: '1/1/2012' ,
    user: 'benbittly', 
    action: 'newIdea', 
    detail: {
        'title': 'how to nest'
        , 'url': '/path/to/idea'
    }

activity: {
    date: '1/2/2012' ,
    user: 'susyq', 
    action: 'editProfile', 
    detail: {
        'displayName': 'Susan Q'
        , 'profileImageSize': '32'
        , 'profileImage': '/path/to/image'
    }
like image 443
Brig Avatar asked Apr 13 '12 17:04

Brig


Video Answer


1 Answers

Use the Mixed type, which allows you to store the arbitrary sub-objects in your example.

var Activity = new Schema({
    date : Date
  , user : String 
  , action : String
  , detail : Mixed
})
like image 61
Kyle Banker Avatar answered Sep 28 '22 05:09

Kyle Banker