Closed linus-amg closed 9 years ago
if i write the following aggregate:
MasterUser.aggregate [
$unwind: '$tenants'
,
$match:
'tenants': new ObjectId(tenantId)
], (err, results) ->
callback err, results
the mongoose debugging does not cast the ObjectId right:
Mongoose: users.aggregate([ { '$unwind': '$tenants' }, { '$match': { tenants: 5586c579936847d236fbdc03 } } ]) {}
the same thing happens if i use the mongoose ObjectId Type:
mongoose.Types.ObjectId(tenantId)
Fun fact i forgot to mention: if i change the arrays item type to string, and search the string, everything works as expected, its only if its of type ObjectId that it doesnt work.
neither does findOne work
Mongoose: users.findOne({ tenants: ObjectId("5580b0695b03e2e592bf722e") }) { fields: undefined }
it works though if the document which im searching is having a string with that id and if im searching for the string instead of using ObjectId()
just found out that it works with version 3.8.31 :)
This looks related to #3079, but I haven't been able to reproduce this in any case. Can you send me the following:
npm list | grep "mongo"
so I can try to debug a little more?
No response for a while. Re-open if this is still an issue.
I am experiencing this issue, did you find any solution to this?
@Davidrl1000 please provide repro instructions / code samples.
experienced the same issue does anyone have fix for this?
experienced the same issue does anyone have fix for this? I found I had this issue because of my import. I was importing a JSON file using MongoDB compass.
hi, great job you are doing with mongoose, thank you very much!
we have one problem though: we can't find documents which have a specific ObjectId in a array of these documents, here I will put an example:
2 example documents of users:
working mongodb query:
failing mongoose queries (not failing.. but returning an empty array..):
We also tried aggregates, unwinding the tenants array and using match, elementMatch whatsoever, the same agregates with the native mongodb driver return the documents which have the Item ObjectId("123"), so i thought it should have something to do with mongoose then.
Having debugging enabled i saw surprisingly that in effect mongoose sends the same query which i am executing in robomongo for example, mongoose does not return anything but the mongo-cli or robomongo with the same query do return what i would expect.
the tenants type inside the user schema is [{ type: mongoose.Schema.Types.ObjectId, ref: 'tenant' }]
im using mongoose 4.0.5
what could i do to make it work?