These are chat archives for Automattic/mongoose

16th
Sep 2016
Felix Itzenplitz
@cebor
Sep 16 2016 10:39
hi, is it possible to call a virtual as default value for a model property ?
i have a field expiresAt and a virtual expiresIn, i want to set expiresAt default to expire in 30 days via the virtual, is this possible ?
oli
@functionsarefun_twitter
Sep 16 2016 12:02
Aloha! Is there any way to access the root Model from a virtual within a subdocument?
ImageSchema.virtual('url').get(function () {
  var parent = this.parent(); //works
  var root = this.root(); //Anything like this available?
  return '/'+root.category+'/'+root.path+'/'+this.name;
});
oli
@functionsarefun_twitter
Sep 16 2016 12:32
solved it with this:
  var parent = this.parent()
  var root = (parent.parent ? parent.parent() : parent)
temuccio
@temuccio
Sep 16 2016 15:35
hello all
temuccio
@temuccio
Sep 16 2016 15:40
I have one problem
I don't try to insert a 2sphere point value
I have this message when try to save
Mongoose: utenti.insert({ _id: ObjectId("57dc11cb37d99b400a79d411"), level: 0, email: '57dc11cb37d99b400a79d411', indirizzo: 'Viale dei Gladiatori 10', cap: '00135', citta: 'Roma', provincia: 'RM', nazione: 'IT', primoaccesso: true, notifica: 0, verify: false, deletedAt: new Date("Fri, 16 Sep 2016 15:37:47 GMT"), geo: { coordinate: [ -110.8571443, 32.4586858 ], type: 'Point' }, __v: 0 }) sono in utente.save { MongoError: Can't extract geo keys: { _id: ObjectId('57dc11cb37d99b400a79d411'), level: 0, email: "57dc11cb37d99b400a79d411", indirizzo: "Viale dei Gladiatori 10", cap: "00135", citta: "Roma", provincia: "RM", nazione: "IT", primoaccesso: true, notifica: 0, verify: false, deletedAt: new Date(1474040267161), geo: { coordinate: [ -110.8571443, 32.4586858 ], type: "Point" }, __v: 0 } Point must be an array or object at Function.MongoError.create (/home/teme/progetto/copisterie3/server/node_modules/mongodb-core/lib/error.js:31:11) at toError (/home/teme/progetto/copisterie3/server/node_modules/mongodb/lib/utils.js:114:22) at /home/teme/progetto/copisterie3/server/node_modules/mongodb/lib/collection.js:620:23 at handleCallback (/home/teme/progetto/copisterie3/server/node_modules/mongodb/lib/utils.js:96:12) at /home/teme/progetto/copisterie3/server/node_modules/mongodb/lib/bulk/unordered.js:473:9 at handleCallback (/home/teme/progetto/copisterie3/server/node_modules/mongodb/lib/utils.js:96:12) at resultHandler (/home/teme/progetto/copisterie3/server/node_modules/mongodb/lib/bulk/unordered.js:420:5) at commandCallback (/home/teme/progetto/copisterie3/server/node_modules/mongodb-core/lib/topologies/server.js:1194:9) at Callbacks.emit (/home/teme/progetto/copisterie3/server/node_modules/mongodb-core/lib/topologies/server.js:119:3) at Connection.messageHandler (/home/teme/progetto/copisterie3/server/node_modules/mongodb-core/lib/topologies/server.js:358:23) at Socket.<anonymous> (/home/teme/progetto/copisterie3/server/node_modules/mongodb-core/lib/connection/connection.js:292:22) at emitOne (events.js:96:13) at Socket.emit (events.js:188:7) at readableAddChunk (_stream_readable.js:176:18) at Socket.Readable.push (_stream_readable.js:134:10) at TCP.onread (net.js:543:20) name: 'MongoError', message: 'Can\'t extract geo keys: { _id: ObjectId(\'57dc11cb37d99b400a79d411\'), level: 0, email: "57dc11cb37d99b400a79d411", indirizzo: "Viale dei Gladiatori 10", cap: "00135", citta: "Roma", provincia: "RM", nazione: "IT", primoaccesso: true, notifica: 0, verify: false, deletedAt: new Date(1474040267161), geo: { coordinate: [ -110.8571443, 32.4586858 ], type: "Point" }, __v: 0 } Point must be an array or object', driver: true, code: 16755, index: 0, errmsg: 'Can\'t extract geo keys: { _id: ObjectId(\'57dc11cb37d99b400a79d411\'), level: 0, email: "57dc11cb37d99b400a79d411", indirizzo: "Viale dei Gladiatori 10", cap: "00135", citta: "Roma", provincia: "RM", nazione: "IT", primoaccesso: true, notifica: 0, verify: false, deletedAt: new Date(1474040267161), geo: { coordinate: [ -110.8571443, 32.4586858 ], type: "Point" }, __v: 0 } Point must be an array or object', getOperation: [Function], toJSON: [Function], toString: [Function] }
temuccio
@temuccio
Sep 16 2016 16:16
How I can see the mongoose version?
Paul "Joey" Clark
@joeytwiddle
Sep 16 2016 16:18
npm list mongoose or grep version node_modules/mongoose/package.json
temuccio
@temuccio
Sep 16 2016 16:19
thanks @joeytwiddle
temuccio
@temuccio
Sep 16 2016 16:50
Do you can help me with a find with $near in 2dspheric?
James
@James1x0
Sep 16 2016 23:38
Is there anyway to cancel a mongoose document save in the pre middleware w/o invoking an error? I have a specific usecase where a save will be deferred to another time, but immediate feedback would be necessary. I know the middleware can overwrite values in "this", therefore rendering a useless save, but I was wondering if there was an easier way.