0

i wont to save object employe without _id i want to save just attribute "employe" As below :

"employe" :[
              {
                    "name" : "leila", 
                    "idemploye" : ObjectId("59319505efa50b137477a1f4"), 
              },
              {
                    "name" : "aicha", 
                    "idemploye" : ObjectId("59319505efa50b137477a1f"),     
              }
            ]

This and the document that records on db with the _id attribute that automatically generates

    { 
            "_id" : ObjectId("59563cb90f62370da8b598fc"), 
            "categorie" : "MAQUILLAGE --> Maquillage Jour", 
            "idsalon" : ObjectId("59318cb0efa50b137477a149"), 
            "idservice" : ObjectId("5931828defa50b137477a137"), 
            "updatedAt" : ISODate("2017-06-30T11:57:45.897+0000"), 
            "createdAt" : ISODate("2017-06-30T11:57:45.897+0000"), 
            "isChecked" : true, 
            "employe" : [
                {
                    "name" : "leila", 
                    "idemploye" : ObjectId("59319505efa50b137477a1f4"), 
                    "_id" : ObjectId("59563cb90f62370da8b598fd")
                },
 {
                    "name" : "aicha", 
                    "idemploye" : ObjectId("59319505efa50b137477a1f"), 
                    "_id" : ObjectId("59563cb90f62370da8b598fb")
                }
            ], 
            "price" : NumberInt(15), 
            "time" : NumberInt(5), 
            "name" : "Forfait Cils et Sourcils", 
            "__v" : NumberInt(0)
        }

my schema for attribut employe is :

 employe: [{
        name :String,
        idemploye: {
            type: mongoose.Schema.Types.ObjectId,
            ref: '_id'
        }
    }]
    ,
Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
ahmed chega
  • 63
  • 1
  • 5

1 Answers1

0

The only way is to create sub schema for your employe attribute like this:

var employeSchema = mongoose.Schema({
  name: String,
  idemploye: {
    type: mongoose.Schema.Types.ObjectId,
    ref: '_id'
  }
}, {
  _id: false
});

var parentSchema = mongoose.Schema({
  ...
  employe: [employeSchema]
});
kaxi1993
  • 4,535
  • 4
  • 29
  • 47