Dynamically add fields to Mongo

297
January 20, 2017, at 07:46 AM

I have an application where I would like to have a user make custom named groups, Im having a hard time figuring out how to have them save properly to the database. At first I was going to have groups saved like,

 groups: [
    {family:{
        type: mongoose.Schema.Types.ObjectId,
        ref: "User"},
        name: String,
        email: String
    },
     {friends:{
        type: mongoose.Schema.Types.ObjectId,
        ref: "User",
         name: String,
         email: String
    }
    },
    {colleagues:{
        type: mongoose.Schema.Types.ObjectId,
        ref: "User",
        name: String,
        email: String
    }
    }],

Then I realized that people should be able to add their own groups like work college or whatever they like.

I am using Mongoose and their schemaModels, so how can something like this mesh with Mongoose?

My application is using Node, so would I just to do...

User.findByIdAndUpdate(id, req.body.groupname, 
  {$push:req.body.group}, function(err, group){
   blah
  }
}

I just thought I would ask before opening up a can of worms, Im unsure if Mongoose would push back, or if $push is the right thing to use.

Rent Charter Buses Company
READ ALSO
sending mail using self hosted mail server Haraka nodejs to Internet

sending mail using self hosted mail server Haraka nodejs to Internet

Just noobs question in smtp server administration, I had simple mail server local setup and is working fine for local networkI want to rent vps service and copy all my either dovecot and haraka setting project to vps for sending and receiving emails

402
'Error: Cannot find module' after fork and patch

'Error: Cannot find module' after fork and patch

I forked an npm package (https://githubcom/spark/particle-api-js), made some changes, used that in a project (https://github

296
Uncaught Error: addComponentAsRefTo after building searchkit v0.10.1

Uncaught Error: addComponentAsRefTo after building searchkit v0.10.1

I'm trying to build this package: https://githubcom/searchkit/searchkit/ (version v0

574
Import text json for node js template literals

Import text json for node js template literals

For my node js projects i typically have a textjson file and require it, instead of having static text within my code

423