These are chat archives for Automattic/mongoose

22nd
Nov 2016
Nguyễn Hoài Nam
@Vietprogrammer_twitter
Nov 22 2016 02:28
But my structure is like that
1.png
Nguyễn Hoài Nam
@Vietprogrammer_twitter
Nov 22 2016 02:39
I resovled, but I still don't understand why the error, the code now is the same above and it works, hix
Michael Leanos
@mleanos
Nov 22 2016 02:46

I'm using Mongoose in a TypeScript project. I'm trying to do a simple validation on ObjectId using the following

let _id = new mongoose.Types.ObjectId(id);
console.log('_id: ', _id);
console.log('isValid: ', _id.isValid);

Outputs..

_id:  5832875c1db84b3590efaf5a
isValid:  undefined
Is anyone able to successfully validate Mongoose ObjectId's in Typescript 2?
Henrik Lundgren
@henriklundgren
Nov 22 2016 12:12
whats the sentiment on writing the schemas as pojo's? I.e.
{ name: 'string', id: 'ObjectId' }
I havent found it documented anywhere, so I dont know the purity of doing it, but it works.
Felix Itzenplitz
@cebor
Nov 22 2016 12:50
hi whats wrong with following schema
let optionSchema = new Schema();
optionSchema.add({
  value: {
    type: String,
    required: true
  },
  text: {
    type: String,
    required: true
  },
  selected: Boolean,
  disabled: Boolean,
  options: [optionSchema]
});
getting max callstack error
erros only when options declared ass array
Michael Leanos
@mleanos
Nov 22 2016 19:38
@cebor It seems to me that this would create an infinite recursive reference, since you're embedding a schema into itself. Thus the max callstack error.
@cebor I didn't see your last comment. So this works when you just declare options as a normal (non array) embedded schema?