These are chat archives for Automattic/mongoose

16th
May 2015
Pedro Machado Santa
@pedrosanta
May 16 2015 00:15
Yeap, I'm trying Mean.js now.
truonguit2010
@truonguit2010
May 16 2015 17:07

@truonguit2010
Hi,

var userSchema = new mongoose.Schema({
    cc : String, // Country code
    pn : {
        cc : String,
        nu : String
    }, // Phone number
    pa : String, // Password
    fn : String, // First name
    ln : String, // Last name
    bd : Date, // Birthday
    em : String, // Email
    al : String, // Avatar link
    sex: Number, // Gender
    stt: Number,
    acd: String,
    c_st: [ObjectId],
    wl : [ObjectId],
    set: {
        lo : {
            lng: Number,
            lat: Number
        },
        cat: [ObjectId],
        key: [String]
    },
    de: [ObjectId],
    m_st: [
        {
            id: ObjectId,
            na: String,
            add: String
        }
    ]
});

What wrong when my create document?

req.models.User.create({'pn.cc' : registerReq.cc , 'pn.nu' : registerReq.pn , acd : activeCode}, function(err, createdUser) {
                    callback(err, createdUser);
                });
I want to create a User with pn.cc and pn.nu , but pn is an embedded document.
/Users/truongps/Documents/capsule/capusle-nodejs/restapi/node_modules/mongoose/lib/document.js:60
    this.set(obj, undefined, true);
         ^

TypeError: Property 'set' of object { _id: 555770e62803d3500f0d35a9,
  m_st: [],
  de: [],
  set: { key: [], cat: [], lo: {} },
  wl: [],
  c_st: [],
  pn: {} } is not a function
    at model.Document (/Users/truongps/Documents/capsule/capusle-nodejs/restapi/node_modules/mongoose/lib/document.js:60:10)
    at model.Model (/Users/truongps/Documents/capsule/capusle-nodejs/restapi/node_modules/mongoose/lib/model.js:43:12)
    at new model (/Users/truongps/Documents/capsule/capusle-nodejs/restapi/node_modules/mongoose/lib/model.js:2536:11)
    at /Users/truongps/Documents/capsule/capusle-nodejs/restapi/node_modules/mongoose/lib/model.js:1540:15
    at Array.forEach (native)
    at Function.create (/Users/truongps/Documents/capsule/capusle-nodejs/restapi/node_modules/mongoose/lib/model.js:1539:8)
    at async.waterfall.message (/Users/truongps/Documents/capsule/capusle-nodejs/restapi/routes/users.js:36:33)
    at fn (/Users/truongps/Documents/capsule/capusle-nodejs/restapi/node_modules/async/lib/async.js:641:34)
    at Object._onImmediate (/Users/truongps/Documents/capsule/capusle-nodejs/restapi/node_modules/async/lib/async.js:557:34)
    at processImmediate [as _immediateCallback] (timers.js:336:15)