ChickenKyiv / api-extended-database-Khyati

GNU General Public License v3.0
0 stars 2 forks source link

run automigrate before calling a mongodb database #8

Closed atherdon closed 6 years ago

atherdon commented 6 years ago

when you'll switch from file with data into database - you'll need to run loopback.automigrate method. i have a samples, so buzz me and i'll move that information here.

5

this is the most recent version of import script that i did: https://github.com/ChickenKyiv/recipe-search-api/tree/master/bin

how to run this script: https://github.com/ChickenKyiv/recipe-search-api/blob/master/package.json#L15

not remember - but it can be broken at this moment. If it will crash - buzz me - and i'll finish it - cause i'm lazy to do it.

nice progress, BTW. we'll need an upload stuff for images soon

khyati0212 commented 6 years ago

Please send me sample details.

atherdon commented 6 years ago

updated

atherdon commented 6 years ago

@khyati0212 we have trobules with Ian on this thing, so don't worry if something will be broken. if i cannot reply fast, dont' spend a lot of time, cause i think this part should be configured more gentle. So i ithink i should be with you, while you're working on this task.

khyati0212 commented 6 years ago

Yeah sure. I am still learning Mongo and Raven. Got stuck with assignment of my certification. Was having final submission of this quarter on thursday. I will finish this in 2 days for sure.

atherdon commented 6 years ago

it's ok - i know that new things is always not easy. Btw, if you're busy - please take your time. it's not a big deal to take some days without coding this project. this will also give me some time :) and good luck with your assignment!

khyati0212 commented 6 years ago

Hi @atherdon I added automigration. But getting mongo : Authentication fail error. Can you check if I am missing something. Here is the full error log.

sudo npm start

reservations@1.0.0 start /mnt/c/GitHub/api-extended-database node .

Connection fails: MongoError: Authentication failed. It will be retried for the next request. AssertionError [ERR_ASSERTION]: campground is referencing a dataSource that does not exist: "reservationDS" at configureModel (/mnt/c/GitHub/api-extended-database/node_modules/loopback/lib/application.js:536:5) at Function.app.model (/mnt/c/GitHub/api-extended-database/node_modules/loopback/lib/application.js:126:5) at /mnt/c/GitHub/api-extended-database/node_modules/loopback-boot/lib/executor.js:203:9 at Array.forEach () at setupModels (/mnt/c/GitHub/api-extended-database/node_modules/loopback-boot/lib/executor.js:199:23) at execute (/mnt/c/GitHub/api-extended-database/node_modules/loopback-boot/lib/executor.js:40:3) at bootLoopBackApp (/mnt/c/GitHub/api-extended-database/node_modules/loopback-boot/index.js:154:3) at Object. (/mnt/c/GitHub/api-extended-database/server/server.js:26:1) at Module._compile (module.js:649:30) at Object.Module._extensions..js (module.js:660:10) at Module.load (module.js:561:32) at tryModuleLoad (module.js:501:12) at Function.Module._load (module.js:493:3) at Function.Module.runMain (module.js:690:10) at startup (bootstrap_node.js:194:16) at bootstrap_node.js:666:3 npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! reservations@1.0.0 start: node . npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the reservations@1.0.0 start script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! /home/khyati/.npm/_logs/2018-04-02T23_30_47_264Z-debug.log

khyati0212 commented 6 years ago

Hi @atherdon did you get chance to look at it?

atherdon commented 6 years ago

no, today i was playing and working with wood - it's clear my mind

khyati0212 commented 6 years ago

Ok. Np.

atherdon commented 6 years ago

as i still hiding - don't want to waste your time waiting. if you have spare time, please check this article. Put all things in one place. it was created for you https://medium.com/p/things-that-should-read-and-use-javascript-intern-at-groceristar-april-18-collection-bd6541e9ae28

khyati0212 commented 6 years ago

I saw it in testing Issue and am going through it. Working on Promises, ES6, testing from the article.

atherdon commented 6 years ago

ohh, you tracking me :) just joking. yeah it was a task where i keep my draft.

atherdon commented 6 years ago

Some information about migrations: first part it's a simple thing, you just need to call automigrate and specify tables that you need to drop. and you need to run that script from CLI

second part is complex and related to importing data from js array into db row.

  1. will be to create a file/files, with arrays(you can grab that data from db.json file)
  2. then you'll need to create a file where you'll actually import data from array into db. as before - you should check the latest version at search-api - and see how i did it here.

btw, i think your issue related to something else, so i'm cloning your repo and will take a look right now

atherdon commented 6 years ago

as i told you before, mongo is the weakiest part of that tutorial. you should try this version: https://github.com/GroceriStar/groceristar/blob/master/server/datasources.json

btw, i think there was a different names of datasources, but maybe it'll be solved after update i got this A datasource is created with name "reservationDS", which is different from the name in settings ("reservationsDS"). Please adjust your configuration to ensure these names match.

atherdon commented 6 years ago

btw, be brave - i'm trying to broke your current git workflow. let's see how you'll solve it :)

khyati0212 commented 6 years ago

Go on. We will find a fix if it gets broke.

atherdon commented 6 years ago

buzz me if new configuration will not solve the error.

khyati0212 commented 6 years ago

should I merge the pull request you created?

atherdon commented 6 years ago

yes, if you reviewed the changes and it's ok

khyati0212 commented 6 years ago

Previous error got resolved. In model-config.json datasource name was wrong.

khyati0212 commented 6 years ago

but now new error is coming. Mongo authentication is failing.

Web server listening at: http://localhost:3000 Browse your REST API at http://localhost:3000/explorer Connection fails: MongoError: Authentication failed. It will be retried for the next request. MongoError: Authentication failed. at /mnt/c/GitHub/api-extended-database/node_modules/mongodb-core/lib/connection/pool.js:598:61 at authenticateStragglers (/mnt/c/GitHub/api-extended-database/node_modules/mongodb-core/lib/connection/pool.js:516:16) at Connection.messageHandler (/mnt/c/GitHub/api-extended-database/node_modules/mongodb-core/lib/connection/pool.js:552:5) at emitMessageHandler (/mnt/c/GitHub/api-extended-database/node_modules/mongodb-core/lib/connection/connection.js:309:10) at Socket. (/mnt/c/GitHub/api-extended-database/node_modules/mongodb-core/lib/connection/connection.js:452:17) at Socket.emit (events.js:180:13) at Socket.emit (domain.js:421:20) at addChunk (_stream_readable.js:269:12) at readableAddChunk (_stream_readable.js:256:11) at Socket.Readable.push (_stream_readable.js:213:10) at TCP.onread (net.js:578:20) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! reservations@1.0.0 start: node . npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the reservations@1.0.0 start script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! /home/khyati/.npm/_logs/2018-04-09T20_37_27_979Z-debug.log

atherdon commented 6 years ago

will check it soon

khyati0212 commented 6 years ago

@atherdon can you try running the app on your system? I think the error is related to mongo connection. I did so much research. Tried installing heroku on local system an other things as well but nothing helped.

atherdon commented 6 years ago

@khyati0212 check in it right now

atherdon commented 6 years ago

not sure, but maybe this comment was missed: https://github.com/ChickenKyiv/api-extended-database/issues/8#issuecomment-379879903 if you compare 2 datasources - you'll see the difference. not a big deal - i was trapped with same issue :) this is why i use mlab and simple version of connector

will try to update datasources on my PC and connect.

atherdon commented 6 years ago

works for me

khyati0212 commented 6 years ago

Did you change anything? Or run the code from this repository?

atherdon commented 6 years ago

If i was you: 1) i'll re-read this comment https://github.com/ChickenKyiv/api-extended-database/issues/8#issuecomment-379879903 2) compare 2 datasources 3) update your datasource 4) paste mlab link from this issue: #5 5) run your project, find maybe(or not) another small issue(that you know how to deal with) 6) profit :)

khyati0212 commented 6 years ago

Great. Thank you for guidance. I will do that.

atherdon commented 6 years ago

no prob. it's just bad tutorial coverage. maybe i need to recreate it, in order to skip that stuff, confusing parts...

soon it will be less buggy. i mean it will be more easy to catch.

khyati0212 commented 6 years ago

finally it worked. what a relief. I understood. Used id and password not specified so authentication was failing. now moving to part 2. :|

atherdon commented 6 years ago

i don't want to steal that feeling from you. but i steal it from Ian - helped him with some small issue.. hope he'll didn't findout :)

On 13-Apr-2018 at 04:45 PM, Khyati wrote:

finally it worked. what a relief.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ChickenKyiv/api-extended-database/issues/8#issuecomment-381194250, or mute the thread https://github.com/notifications/unsubscribe-auth/ABZrDqY7SLeEHmmwdQDeO9qDPNMMxH04ks5toNYogaJpZM4SuZsq .

atherdon commented 6 years ago

still, you didn't do it well. please re-read again that comment related to datasources.

khyati0212 commented 6 years ago

no no i haven't updated the code yet on git let me do it. After that i will do second step of that comment

atherdon commented 6 years ago

will close this task, and move info into migration into another

khyati0212 commented 6 years ago

Now uploaded code for first step of comment #8. Will work on second step and let you know sooon

atherdon commented 6 years ago

got it. btw, it's good that you catched the name of datasource in migrate file. i got that as error frequently

On 13-Apr-2018 at 07:00 PM, Khyati wrote:

no no i haven't updated the code yet on git let me do it. After that i will do second step of that comment

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ChickenKyiv/api-extended-database/issues/8#issuecomment-381231686, or mute the thread https://github.com/notifications/unsubscribe-auth/ABZrDp9ukmz_MRND5fZlguPkR8D7kbU1ks5toPXPgaJpZM4SuZsq .