Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrating Existing, Strapi App from Using Sqlite3 to Using MongoDB

Tags:

mongodb

strapi

I have a local, strapi app (that I have in a git repo) that I want to migrate from using sqlite3 to using mongodb

I have done the following:

  • created a 2nd, temporary, strapi app that is successfully using mongodb from the start (so I have a good mongo instance running locally)

  • copied the database.json content from the temp, working-mongodb, strapi app to my existing one. (made sure was in development and ran development version)

From my existing app (from which I want to use mongodb), I

  • uninstalled:

    • strapi-hook-bookshelf

    • strapi-hook-knex

    • knex

    • sqlite3

  • installed strapi-hook-mongoose

NOTES:

  • the existing app (from which i want to use mongodb) runs successfully if I keep just keep using sqlite3.
  • i created the existing app using the quickstart option

But, I still get this error...terminal output, snippet below 👇

Terminal Output Snippet:

(node:37499) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.
(node:37499) UnhandledPromiseRejectionWarning: TypeError: orm.load(...).buildQuery is not a function
    at buildQuery (/Users/monico_a_moreno/source/.../folder-strapi-poc/node_modules/strapi-utils/lib/buildQuery.js:122:21)
    at Object.count (/Users/monico_a_moreno/source/.../folder-strapi-poc/node_modules/strapi-plugin-users-permissions/config/queries/mongoose.js:18:12)
    at Object.initialize (/Users/monico_a_moreno/source/.../folder-strapi-poc/node_modules/strapi-plugin-users-permissions/services/UsersPermissions.js:502:8)
    at module.exports (/Users/monico_a_moreno/source/.../folder-strapi-poc/node_modules/strapi-plugin-users-permissions/config/functions/bootstrap.js:156:65)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:37499) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:37499) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
[2019-07-03T18:27:15.985Z] warn The bootstrap function is taking unusually long to execute (3500 miliseconds).
[2019-07-03T18:27:15.986Z] warn Make sure you call it?

    What am I doing wrong? 🤔  


like image 708
Monico Moreno Avatar asked Jul 03 '19 18:07

Monico Moreno


People also ask

Can we use MongoDB with Strapi?

If you want to safely store your Strapi content in MongoDB, sign up for MongoDB Atlas for free. Happy content creation!

Is NoSQL a Strapi?

Strapi supports both NoSQL and SQL databases. Changing the database is as simple as changing the env variable in the configuration folder. By default, Strapi uses SQLite, which is good for local testing, but in production you should use a production-ready database such as PostgreSQL or MySQL. We'll use PostgreSQL here.


1 Answers

This is cool! I can answer my own question! 😜

Seriously though, I am answering my own question for the benefit of others that might run into the same issue.

Bottom line: I had the wrong version of strapi-hook-mongoose installed.

Details: When I installed strapi-hook-mongoose, I didn't specify a version, and so, npm installed ^3.0.0-alpha.13, and due to the fact that my existing, strapi project is on the (then) latest v3.0.0-beta.7, it failed to run (gave the error described in the above description).

Solution: Uninstall the package and re-install, explicitly specifying the version 👇

npm i [email protected] 🙌

like image 187
Monico Moreno Avatar answered Sep 29 '22 08:09

Monico Moreno