These are chat archives for Automattic/mongoose

4th
Jan 2016
Valeri Karpov
@vkarpov15
Jan 04 2016 13:52
@Ldiab it'll fire find hooks, populate() is just a find()
@michaelfavia yep but we don't really have docs for this feature yet, see tests for example: https://github.com/Automattic/mongoose/blob/master/test/model.populate.test.js#L2791
@puradawid nope, not possible to do async virtuals because = can't be an async operation. You can of course make a virtual return a promise
@uptownhr @jontonsoup There's also https://github.com/mnort9/goosecon . I've been playing around with writing an alternative to robomongo because robomongo doesn't fully support mongodb 3.x
Valeri Karpov
@vkarpov15
Jan 04 2016 13:57
@BerndErnst holiday season in the US has that effect sometimes :)
Luis Miguel Díaz Abril
@EyLuismi
Jan 04 2016 13:59
Excelent, thanks @vkarpov15 and Do you think the populate method will be using Joins from Mongodb 3.2 any time soon? Just curious
Valeri Karpov
@vkarpov15
Jan 04 2016 15:44
@Ldiab nope, because $lookup only works in the aggregation framework
Joseph Thibeault
@jrthib
Jan 04 2016 18:06
what is the best way to sanitize user inputs with mongoose to prevent injection attacks?
Mongoose casts to the correct type but you will need to do your own checking if using $where etc
Joseph Thibeault
@jrthib
Jan 04 2016 18:09
ah ok good to know
Luis Miguel Díaz Abril
@EyLuismi
Jan 04 2016 19:26
@vkarpov15 Ok, thanks!
John Grogg
@johngrogg
Jan 04 2016 21:00
I'm running into a validation error related to an embedded document's _id. Anyone have any guidance on what could be causing it? Error is: CastError: Cast to ObjectID failed for value "[object Object]" at path "_id"
The embedded document looks like this in the schema
packIns: [{
        itemId: Number,
        item: { type: Schema.Types.ObjectId, ref: 'Item' },
        inserted: { type: Boolean, default: false }
    }],
and the error is on path packIns.0._id, which should be being set automatically
and the actual value of the path is { _bsontype: 'ObjectID', id: 'Sûˆ\\BÚb/ò¢\u001b' } as logged to console
Valeri Karpov
@vkarpov15
Jan 04 2016 21:03
hmm @johngrogg how are you generating the _id?
John Grogg
@johngrogg
Jan 04 2016 21:03
I'm not, the underlying Mongoose default middleware is handling that
Valeri Karpov
@vkarpov15
Jan 04 2016 21:03
this error usually happens if you have 2 different versions of mongoose installed or a separate version of the mongodb driver installed somewhere that conflicts
John Grogg
@johngrogg
Jan 04 2016 21:04
ahh, ok, I'll triple check for that
Valeri Karpov
@vkarpov15
Jan 04 2016 21:04
also if I were you I'd double check that you're not setting _id anywhere
John Grogg
@johngrogg
Jan 04 2016 21:06
already did that. logging out the packIns before validation results in a nice [{ item: 568abec88ae77137016b97c7, itemId: 1827, inserted: true }]
is there a way in code to tell which version of mongoose and the mongodb driver is being used? From what I can tell mongoose is only installed once with version 4.3.4, and mongodb drive 2.1.2
could it be an issue from an older version of nodejs itself?
Night Monkey
@NightAOtidae
Jan 04 2016 21:11

Given this

{ "AVX349a-c481-4f22-97ac-aa335d383060": {
    "id": "DBED9a-c481-4f22-97ac-aa335d383060",
    "name": "Some Group",
    "desc": "This group is used for data that blah blah blah",
    "otherdata": {},
    "sub_data": {}
  }

How can you create a schema for this? I have a lot of data that is basically tree/pure json based where I need the keys to be static UUID's. Is there a way to do this?

John Grogg
@johngrogg
Jan 04 2016 21:23
hmm...nope, tried with node 0.12.9 and still same error
John Grogg
@johngrogg
Jan 04 2016 21:36
and found the issue, the data that was creating the parent object did have an _id value for the packIns embedded doc, but for some reason in the context I was originally logging the source data out in, it wasn't printing the _id field