[GH-ISSUE #436] Cannot use mongodb adapter #16905

Closed
opened 2026-04-15 14:52:43 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @yashwanth2804 on GitHub (Nov 6, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/436

Argument of type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").Db' is not assignable to parameter of type 'Db'.
  Types of property 'createCollection' are incompatible.
    Type '<TSchema extends Document = import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/bson@6.9.0/node_modules/bson/bson").Document>(name: string, options?: import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/m...' is not assignable to type '<TSchema extends Document = Document>(name: string, options?: CreateCollectionOptions | undefined) => Promise<Collection<TSchema>>'.
      Types of parameters 'options' and 'options' are incompatible.
        Type 'CreateCollectionOptions | undefined' is not assignable to type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").CreateCollectionOptions | undefined'.
          Type 'CreateCollectionOptions' is not assignable to type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").CreateCollectionOptions'.
            Types of property 'session' are incompatible.
              Type 'ClientSession | undefined' is not assignable to type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").ClientSession | undefined'.
                Type 'ClientSession' is not assignable to type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").ClientSession'.
                  Types of property 'clientOptions' are incompatible.
                    Type 'MongoOptions | undefined' is not assignable to type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").MongoOptions | undefined'.
                      Type 'MongoOptions' is not assignable to type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").MongoOptions'.
                        The types of 'autoEncryption.keyVaultClient' are incompatible between these types.
                          Type 'MongoClient | undefined' is not assignable to type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").MongoClient | undefined'.
                            Type 'MongoClient' is not assignable to type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").MongoClient'.
                              Types of property 'bulkWrite' are incompatible.
                                Type '<SchemaMap extends Record<string, Document> = Record<string, Document>>(models: readonly ClientBulkWriteModel<SchemaMap>[], options?: ClientBulkWriteOptions | undefined) => Promise<...>' is not assignable to type '<SchemaMap extends Record<string, Document> = Record<string, import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/bson@6.9.0/node_modules/bson/bson").Document>>(models: readonly import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-ho...'.
                                  Types of parameters 'options' and 'options' are incompatible.
                                    Type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").ClientBulkWriteOptions | undefined' is not assignable to type 'ClientBulkWriteOptions | undefined'.
                                      Type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").ClientBulkWriteOptions' is not assignable to type 'ClientBulkWriteOptions'.
                                        Types of property 'session' are incompatible.
                                          Type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").ClientSession | undefined' is not assignable to type 'ClientSession | undefined'.
                                            Type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").ClientSession' is not assignable to type 'ClientSession'.
                                              Types of property 'clientOptions' are incompatible.
                                                Type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").MongoOptions | undefined' is not assignable to type 'MongoOptions | undefined'.
                                                  Type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").MongoOptions' is not assignable to type 'MongoOptions'.
                                                    The types of 'autoEncryption.keyVaultClient' are incompatible between these types.
                                                      Type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").MongoClient | undefined' is not assignable to type 'MongoClient | undefined'.
                                                        Type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").MongoClient' is not assignable to type 'MongoClient'.
                                                          Types of property 'withSession' are incompatible.
                                                            Type '{ <T = any>(executor: import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").WithSessionCallback<T>): Promise<...>; <T = any>(options: import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-h...' is not assignable to type '{ <T = any>(executor: WithSessionCallback<T>): Promise<T>; <T = any>(options: ClientSessionOptions, executor: WithSessionCallback<T>): Promise<...>; }'.
                                                              Types of parameters 'executor' and 'options' are incompatible.
                                                                Type 'ClientSessionOptions' is not assignable to type 'WithSessionCallback<any>'.
                                                                  Type 'ClientSessionOptions' provides no match for the signature '(session: ClientSession): Promise<any>'.ts(2345)

code

import { betterAuth } from 'better-auth';
import { mongodbAdapter } from 'better-auth/adapters/mongodb';
import { MongoClient } from 'mongodb';

const client = new MongoClient("mongodb://localhost:27017/better_auth?retryWrites=true&w=majority");
const db = client.db()
export const auth = betterAuth({
    database: mongodbAdapter(db)
});

versions in package

"better-auth": "^0.7.3",
"mongodb": "^6.10.0",

image

Originally created by @yashwanth2804 on GitHub (Nov 6, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/436 ``` Argument of type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").Db' is not assignable to parameter of type 'Db'. Types of property 'createCollection' are incompatible. Type '<TSchema extends Document = import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/bson@6.9.0/node_modules/bson/bson").Document>(name: string, options?: import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/m...' is not assignable to type '<TSchema extends Document = Document>(name: string, options?: CreateCollectionOptions | undefined) => Promise<Collection<TSchema>>'. Types of parameters 'options' and 'options' are incompatible. Type 'CreateCollectionOptions | undefined' is not assignable to type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").CreateCollectionOptions | undefined'. Type 'CreateCollectionOptions' is not assignable to type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").CreateCollectionOptions'. Types of property 'session' are incompatible. Type 'ClientSession | undefined' is not assignable to type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").ClientSession | undefined'. Type 'ClientSession' is not assignable to type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").ClientSession'. Types of property 'clientOptions' are incompatible. Type 'MongoOptions | undefined' is not assignable to type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").MongoOptions | undefined'. Type 'MongoOptions' is not assignable to type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").MongoOptions'. The types of 'autoEncryption.keyVaultClient' are incompatible between these types. Type 'MongoClient | undefined' is not assignable to type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").MongoClient | undefined'. Type 'MongoClient' is not assignable to type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").MongoClient'. Types of property 'bulkWrite' are incompatible. Type '<SchemaMap extends Record<string, Document> = Record<string, Document>>(models: readonly ClientBulkWriteModel<SchemaMap>[], options?: ClientBulkWriteOptions | undefined) => Promise<...>' is not assignable to type '<SchemaMap extends Record<string, Document> = Record<string, import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/bson@6.9.0/node_modules/bson/bson").Document>>(models: readonly import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-ho...'. Types of parameters 'options' and 'options' are incompatible. Type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").ClientBulkWriteOptions | undefined' is not assignable to type 'ClientBulkWriteOptions | undefined'. Type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").ClientBulkWriteOptions' is not assignable to type 'ClientBulkWriteOptions'. Types of property 'session' are incompatible. Type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").ClientSession | undefined' is not assignable to type 'ClientSession | undefined'. Type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").ClientSession' is not assignable to type 'ClientSession'. Types of property 'clientOptions' are incompatible. Type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").MongoOptions | undefined' is not assignable to type 'MongoOptions | undefined'. Type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").MongoOptions' is not assignable to type 'MongoOptions'. The types of 'autoEncryption.keyVaultClient' are incompatible between these types. Type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").MongoClient | undefined' is not assignable to type 'MongoClient | undefined'. Type 'import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").MongoClient' is not assignable to type 'MongoClient'. Types of property 'withSession' are incompatible. Type '{ <T = any>(executor: import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-hono-app/node_modules/.pnpm/mongodb@6.10.0/node_modules/mongodb/mongodb").WithSessionCallback<T>): Promise<...>; <T = any>(options: import("/root/RealCoaderLinux/Non_codePart/react-hono-sample-test-monorepo/react-h...' is not assignable to type '{ <T = any>(executor: WithSessionCallback<T>): Promise<T>; <T = any>(options: ClientSessionOptions, executor: WithSessionCallback<T>): Promise<...>; }'. Types of parameters 'executor' and 'options' are incompatible. Type 'ClientSessionOptions' is not assignable to type 'WithSessionCallback<any>'. Type 'ClientSessionOptions' provides no match for the signature '(session: ClientSession): Promise<any>'.ts(2345) ``` > code ``` import { betterAuth } from 'better-auth'; import { mongodbAdapter } from 'better-auth/adapters/mongodb'; import { MongoClient } from 'mongodb'; const client = new MongoClient("mongodb://localhost:27017/better_auth?retryWrites=true&w=majority"); const db = client.db() export const auth = betterAuth({ database: mongodbAdapter(db) }); ``` versions in package "better-auth": "^0.7.3", "mongodb": "^6.10.0", ![image](https://github.com/user-attachments/assets/b927abd6-c4b7-4aee-b1f4-8caf63cc1c6f)
GiteaMirror added the locked label 2026-04-15 14:52:43 -05:00
Author
Owner

@Bekacru commented on GitHub (Nov 8, 2024):

this has been fixed since 0.7.5 feel free to reopen if not

<!-- gh-comment-id:2464219167 --> @Bekacru commented on GitHub (Nov 8, 2024): this has been fixed since `0.7.5` feel free to reopen if not
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#16905