Yogev Lahyani
Yogev Lahyani

Reputation: 1

@nestjs/mongoose serializeInto is not a function

I'm trying to execute a mongodb aggregation using @nestjs/mongoose and I'm passing the following query:

$match: {
  organizationId: new ObjectId(organizationId),
}

When I'm passing the organizationId as plain string I get no results, when I'm passing an instance of ObjectId (imported from bson / mongodb / mongoose packages) I'm getting the follwing error:

{
  "type": "TypeError",
  "message": "value.serializeInto is not a function",
  "stack":
  TypeError: value.serializeInto is not a function
  at serializeObjectId (/packages/database/node_modules/mongodb/node_modules/bson/src/parser/serializer.ts:240:18)
  at serializeInto (/packages/database/node_modules/mongodb/node_modules/bson/src/parser/serializer.ts:892:17)
  at serializeObject (/packages/database/node_modules/mongodb/node_modules/bson/src/parser/serializer.ts:295:20)
  at serializeInto (/packages/database/node_modules/mongodb/node_modules/bson/src/parser/serializer.ts:875:17)
  at serializeObject (/packages/database/node_modules/mongodb/node_modules/bson/src/parser/serializer.ts:295:20)
  at serializeInto (/packages/database/node_modules/mongodb/node_modules/bson/src/parser/serializer.ts:655:17)
  at serializeObject (/packages/database/node_modules/mongodb/node_modules/bson/src/parser/serializer.ts:295:20)
  at serializeInto (/database/node_modules/mongodb/node_modules/bson/src/parser/serializer.ts:875:17)
  at Object.serialize (/packages/database/node_modules/mongodb/node_modules/bson/src/bson.ts:108:30)
  at OpMsgRequest.serializeBson (/packages/database/node_modules/mongodb/src/cmap/commands.ts:572:17)
}

It's happening when using find method as well. Anyone encountered this issue? is there a way to simply query the database to find documents that match an ObjectId (not _id)

I tried to debug it with break points, seems that serializeInto is not ObjectId method, so why bson and mongoose uses this?

Upvotes: 0

Views: 162

Answers (1)

Adrian Andersen
Adrian Andersen

Reputation: 11

Updating mongoose and mongodb to latest worked for me.

Upvotes: 1

Related Questions