MongoDB: database name must be a string
See original GitHub issueIssue type:
[ * ] question [ * ] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ * ] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[ ] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native
TypeORM version:
[ * ] latest
[ ] @next
[ ] 0.x.x
(or put your version here)
Steps to reproduce or a small repository showing the problem:
Create a default project with command
typeorm init --name test --database mongdb --express
cd test
yarn install
yarn start
You can see the following error :
{ MongoError: database name must be a string
at Function.MongoError.create (/app/node_modules/mongodb-core/lib/error.js:31:11)
at validateDatabaseName (/app/node_modules/mongodb/lib/db.js:1680:57)
at new Db (/app/node_modules/mongodb/lib/db.js:156:3)
at Db.db (/app/node_modules/mongodb/lib/db.js:1208:12)
at MongoQueryRunner.getCollection (/app/src/driver/mongodb/MongoQueryRunner.ts:803:40)
at MongoQueryRunner.<anonymous> (/app/src/driver/mongodb/MongoQueryRunner.ts:272:27)
at step (/app/node_modules/typeorm/driver/mongodb/MongoQueryRunner.js:32:23)
at Object.next (/app/node_modules/typeorm/driver/mongodb/MongoQueryRunner.js:13:53)
at /app/node_modules/typeorm/driver/mongodb/MongoQueryRunner.js:7:71
at new Promise (<anonymous>)
name: 'MongoError',
message: 'database name must be a string',
driver: true }
My ormconfig.json file :
{
"type": "mongodb",
"database": "test",
"synchronize": true,
"logging": false,
"entities": [
"src/entity/**/*.ts"
],
"migrations": [
"src/migration/**/*.ts"
],
"subscribers": [
"src/subscriber/**/*.ts"
],
"cli": {
"entitiesDir": "src/entity",
"migrationsDir": "src/migration",
"subscribersDir": "src/subscriber"
}
}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:8 (3 by maintainers)
Top Results From Across the Web
'database name must be a string' Error when connecting with ...
I am attempting to connect to MongoDB via the package mongoose , but get an error along the lines of MongoError: database name...
Read more >MongoError: database name must be a string - JavaScript
I'm using replit and I can't connect to my database for the first challenge, Here's what my code looks like: const mongoose ...
Read more >Connection String URI Format — MongoDB Manual
Set the Kerberos service name when connecting to Kerberized MongoDB instances. This value must match the service name set on MongoDB instances to...
Read more >Fix “index name must be a string” when Dropping Multiple ...
If you encounter the “index name must be a string” error when dropping multiple indexes in MongoDB, it's probably because you're passing the ......
Read more >MongoDbUtils (Spring Data MongoDB 1.9.5.RELEASE API)
Mongo mongo, String databaseName). Obtains a DB connection for the given Mongo instance and database name. Parameters: mongo - the Mongo instance, must...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I faced this issue and the problem was that somehow it previously worked without specifying a collection name, but now it needs one.
So…
gave this error. But then I specified the collection name
admin
in this way:and the error vanished.
Thanks documentation
THIS ANSWER WAS EDITED AS THE PREVIOUS ONE LEAD TO OTHER ERRORS I was able to fix the error by adding the following to
mongoose.connect()
function:useMongoClient: true