Using $lookup on collectionname including underscore

I need to do a $lookup against a collection that have starts with a number and has underscore (_) in the name.

using the below is not working. what is best practies when doing this lookup?

from: 12collection_name

Hi @Eirik_Andersen

What version shell/driver and mongodb are you using?

This works for me in mongosh

s0 [primary] test>{$lookup:{from: "61thing_foo", localField: 'b', foreignField:'_id',as: 'x'}})
    _id: ObjectId("6472b1eb000b5a7208da81ba"),
    a: 'one',
    b: 1,
    x: [ { _id: 1, t: 'some words' } ]

Hi Chris,
Sorry, forgot to mention the version. We are running on MongoDB 4.4.


it looks like you are not putting the name within quotes. In most programming languages, this means you are using a variable. In most programming languages, variables cannot start with numbers. I would try with

from: "12collection_name"

as shown in Chris’ example.

Hi steevej,

Already tried that, and it doesn’t help.

Hi @Eirik_Andersen
did you also try single quotes? ’ instead of " ?
Can’t imagine that this really solves it, just to not miss this point out.
The exact error, your code, env setup might be helpful to share.

Show the code you are using and share any error/warning message you are getting.

1 Like