SvelteKit | Mongodb connect | using projections to get data faster!

  Рет қаралды 3,609

Consulting Ninja

Consulting Ninja

Күн бұрын

This is a good one! I walk through hooking up a Dockerized Mongodb instance to a SvelteKit application. Though this works exactly the same with the cloud version. I show what you need to install, how to setup and import your URI (another video link below for more on environment variables in SvelteKit). I show how to fix serializing the mongo _id field if you need to keep that value. I show how to load data into your app. I also show how to use projections to speed up your Mongodb calls to make your application faster! I hope you find this helpful!
My channel membership is live check it out here!:
/ @consultingninja
Membership perk video:
• I launched a chatbot w...
Need help? visit www.consulting...
Check out my channel ‪@ConsultingNinja‬ for more videos like these.
Source Code available here:
github.com/con...
Mongo DB Projection Docs:
www.mongodb.co...
Environment Variable Video:
• SvelteKit | $env modul...
SvelteKit Sandbox:
learn.svelte.d...
SvelteKit Docs:
kit.svelte.dev/

Пікірлер: 25
@marlopainter8246
@marlopainter8246 Жыл бұрын
11:00 - I was getting this error and thought it 'wasn't working' and scrapped my attempt and started over... Then I find this video and see how quick the fix was! Thank you for this! I'm new to Svelte/Kit/TS/Mongo and some of these things are still unknown. I appreciate your videos.
@ConsultingNinja
@ConsultingNinja Жыл бұрын
I am so glad you found this helpful! You are most welcome! I need to circle back to Mongo since there is so much more there to cover. Feel free to share my channel with anyone else that may find my content helpful.
@WhiteVanyo
@WhiteVanyo Жыл бұрын
@@ConsultingNinja Depending on if you actually need a String of the ObjectId or not, I definitely prefer this: let user = await User.findOne().select('-_id').lean();
@ConsultingNinja
@ConsultingNinja 11 ай бұрын
Thank you for sharing!
@mikejohneviota9293
@mikejohneviota9293 Жыл бұрын
I'll share this to my friends
@ConsultingNinja
@ConsultingNinja Жыл бұрын
Thank you! I really appreciate that.
@ScriKidding-eg6vn
@ScriKidding-eg6vn Жыл бұрын
OMG, i was looking for this for a long time. Can you do Full CRUD with SvelteKit + MongoDB sir?
@ConsultingNinja
@ConsultingNinja Жыл бұрын
I am already working on it! :) It is a photo application that I am making for a friend and will deploy to either Fly.io or Linode. Sit back and enjoy the videos as we get there!
@heyjitendra
@heyjitendra Жыл бұрын
You make awesome content. Thank you so much
@ConsultingNinja
@ConsultingNinja Жыл бұрын
I appreciate that!Thank you for watching!
@mikejohneviota9293
@mikejohneviota9293 Жыл бұрын
I love you sir
@ConsultingNinja
@ConsultingNinja Жыл бұрын
I hope that this video helped you!
@pavithpriyadarshan9010
@pavithpriyadarshan9010 10 ай бұрын
Hai sir. May I know how to view this data as an output in our localhost.
@ConsultingNinja
@ConsultingNinja 10 ай бұрын
You can simply add a console.log where you need and view the results in your command prompt or terminal. You need to have started your development server in a command prompt or terminal in order to do this. If you run into a specific error come back and let me know.
@jimshadrick479
@jimshadrick479 Жыл бұрын
Its interesting that I ran across your video and was watching it to see what your approach was to connecting to Mongo. Then in the video you showed the same error that I previously ran into and spent a ton of time researching - "Error: Data returned from `load` while rendering / is not serializable: Cannot stringify arbitrary non-POJOs". After many painstaking attempts to find a solution, I ran across another approach that seemed to work for me - using the `structuredClone' function below. I plan on trying your approach as well to see how that works. Thanks for putting this video out. return { books: structuredClone(data) };
@ConsultingNinja
@ConsultingNinja Жыл бұрын
That is because structuredClone is handling serialization for you under the hood. There may be a slight performance boost using structuredClone actually in some instances (when dealing with large or complex objects), but in this instance since we only need a shallow copy this way should be faster.
@ConsultingNinja
@ConsultingNinja Жыл бұрын
One last note, if you pass something that is not serializable to structureClone it will puke, just an fyi.
@annismonadjem6901
@annismonadjem6901 Жыл бұрын
Kindly explain what is the purpose of creating `client.connect()` at [5:07] ?
@ConsultingNinja
@ConsultingNinja Жыл бұрын
Of course. So client.connect() is explicitly attempting to connect to the mongodb service at the URI that was provided. This is a way of checking that all your service is running, your URI / Credentials (if provided) all are working and this client can communicate with the service. This has been optional now though since version 4.7. You can remove and restructure this example if you don't want to explicitly check the connection before attempting other commands. Great question!
@annismonadjem6901
@annismonadjem6901 Жыл бұрын
@@ConsultingNinja Similar read from mongo manual. Glad you are using the most updated approach.
@OoZAGoO
@OoZAGoO Жыл бұрын
So, do you think there is still a need for NodeJS+Express, etc. as you used in your earlier tutorials or can/should I only use SvelteKit?
@ConsultingNinja
@ConsultingNinja Жыл бұрын
NOPE! With SvelteKit 1.0 you do NOT need any node js or express! SvelteKit is back AND front end! I am loving putting these together. It is really straight forward and I will do a video showcasing an entire application using only SvelteKit and MongoDb . You just need to keep this in mind when you are planning deployment, you have to deploy someplace that provides an actual server. I hope this makes sense. Let me know if you have any other questions!
@OoZAGoO
@OoZAGoO Жыл бұрын
@@ConsultingNinja Thanks for the answer. Current server is clear, I would also need for NodeJS, etc.. Many servers are still PHP only. A video about it would be great. By the way: How about an app that allows user authentication incl. roles etc. in the protected admin area, and makes these roles available via JWT for the public area, so that logged in and authorized users can delete, edit etc. things. This could even be a simple ToDo, where not logged in users can only see the ToDos, but not edit them. So you would have a blueprint on which you can build everything else. Also for later projects. Just a suggestion.
@ConsultingNinja
@ConsultingNinja Жыл бұрын
I have an auth app video, you can check that here: kzbin.info/www/bejne/emO2Y3R_fsSJhrM. (I have another video focusing on protected routes here: kzbin.info/www/bejne/eYuqc5iHeqt8r6s) You can take that auth app and add roles, otherwise I am going to have roles in the app I am making now.
@annismonadjem6901
@annismonadjem6901 Жыл бұрын
@@ConsultingNinja just Sveltekit and Mongodb - that would be really exciting.
Svelte | Real world register form example using SvelteKit and Mongo!
39:15
The intro to Docker I wish I had when I started
18:27
typecraft
Рет қаралды 113 М.
Officer Rabbit is so bad. He made Luffy deaf. #funny #supersiblings #comedy
00:18
Funny superhero siblings
Рет қаралды 7 МЛН
OYUNCAK MİKROFON İLE TRAFİK LAMBASINI DEĞİŞTİRDİ 😱
00:17
Melih Taşçı
Рет қаралды 12 МЛН
From Small To Giant Pop Corn #katebrush #funny #shorts
00:17
Kate Brush
Рет қаралды 70 МЛН
Which One Is The Best - From Small To Giant #katebrush #shorts
00:17
Protect SvelteKit Routes with Hooks
21:10
Huntabyte
Рет қаралды 57 М.
Redis Crash Course
27:31
Web Dev Simplified
Рет қаралды 628 М.
How To Connect to MongoDB in Svelte Kit
27:41
Syntax
Рет қаралды 15 М.
58-Creating APIs with Express.js (Urdu/Hindi)
5:20
TechTales By Rafay
Рет қаралды 31
Understand How Data Flows Through SvelteKit
25:59
Joy of Code
Рет қаралды 19 М.
Learn SvelteKit Hooks Through 6 Examples
23:55
Joy of Code
Рет қаралды 19 М.
Practical Svelte 5 - Shopping Cart
25:10
Huntabyte
Рет қаралды 16 М.
SvelteKit Authentication with PocketBase
31:50
Huntabyte
Рет қаралды 32 М.
Svelte UI Libraries Have Leveled Up
12:14
Huntabyte
Рет қаралды 60 М.
Officer Rabbit is so bad. He made Luffy deaf. #funny #supersiblings #comedy
00:18
Funny superhero siblings
Рет қаралды 7 МЛН