These are chat archives for Automattic/mongoose

23rd
Jul 2015
bruce
@sqram
Jul 23 2015 01:09
creating a schema, how can i create a key whose value is an array of objects?
foo : [Object] ? (but then how would you define the key/values of that object? couldnt find in the docs how to do it,
Felix Milea-Ciobanu
@felixmc
Jul 23 2015 02:50
@sqram you can just do something like: "foo: [{ prop1: String, prop2: Number }]"
basically define a custom objet schema and wrap it in [ ]
bruce
@sqram
Jul 23 2015 04:39
oh thank you
Klaus Dahlén
@nanuuki
Jul 23 2015 11:39

Hi! I'm using Mongoose 3.8.27. I'm trying to use myObj.toJSON() in my tests and ran into a problem with an ObjectId field with a ref to another schema (inside an Array):

...
+ expected - actual
...
      -    "user": {
      -      "_bsontype": "ObjectID"
      -      "id": "U°Ðêñ¹]\u0015‰w"
      -    }
      +    "user": "55b0d08feaf1b95d158f8977"
...

What's the best way to get the user field as a string (as the expected value) instead of the object with _bsontype and id?