Find method is not working correctly

Hello,
I have big issue with .find

.find(
            { _id: { $in: [

                mongoose.Types.ObjectId('61dd423f973c056d38f8355f'),

                mongoose.Types.ObjectId('61ddb79da7305b00090f8c38'),

                mongoose.Types.ObjectId('61dd3a44973c056d38f8355e'),

              ] } },

        )

But this code works (updateMany):

.updateMany(

            { _id: { $in: [
                mongoose.Types.ObjectId('61dd423f973c056d38f8355f'),
                mongoose.Types.ObjectId('61ddb79da7305b00090f8c38'),
                mongoose.Types.ObjectId('61dd3a44973c056d38f8355e'),
              ] } },

            [ {$set : {

                "status": data.toState,

                "generatedToOrder": data.ordered,

                "date_modified": data.date_modified,

                "clientIp": data.clientIp

            }}

        ],

        )

Error in .find:
TypeError [ERR_INVALID_ARG_TYPE]: The "string" argument must be of type string or an instance of Buffer or ArrayBuffer.

I don’t know why, but .find $in not working as .updateMany $in

1 Like

Mongoose Model.find( f i l t e r ) method accepts

filter: Object | ObjectId

In the mongoose docs for ObjectId, the latter is built from

mongoose.ObjectId(...)

as far as I understand from the docs.

So you could try that.

It may not be useful here, but there is also Model.findById(id) where the id can be any type :slight_smile: !