Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a dictionary schema with Mongoose

I am trying to store a dictionary of objects using Mongoose. Realizing that I lose the change detection for saving with using the Mixed type, I was hoping I could create a schema that would not require the Mixed type.

There are plenty of examples of creating schemas for arrays of objects, but not dictionaries of objects. Is it possible to do this?

Format:

{
    ObjectId : {
        "attempts" : {
            "response" : String,
            "timestamp" : Date
        },
        "complete" : Boolean
    }
}
like image 532
Franz Payer Avatar asked Jul 30 '14 07:07

Franz Payer


1 Answers

Update: from 5.1 mongoose have a Map type: https://mongoosejs.com/docs/schematypes.html#maps

like image 130
rssh Avatar answered Sep 27 '22 20:09

rssh