Posts

Showing posts with the label Database

Connect with Oracle DB in Node JS

Image
Let's see how can we connect with oracle db in node js project or lambda Oracle DB - Education Funda First step is to install oracle db package with below command: ~ npm i  oracledb Let's see the code for connecting with oracle db for lambda handler: const oracledb = require ( "oracledb" ); oracledb . outFormat = oracledb . OUT_FORMAT_OBJECT ; exports . handler = async ( event , context , callback ) => { let connection ; const uatConnObj = { user : "db_user_name" , password : "db_pass" , connectString : "ip:port/db" , poolMax : 1 , poolMin : 0 , poolIncrement : 10 , }; const prodConnObj = { user : "db_user_name" , password : "db_pass" , connectString : "ip:port/db" , poolMax : 1 , poolMin : 0 , poolIncrement : 10 , }; try { await oracledb . createPool ( prodConnObj ); let dbPool = oracledb . getPool (); ...

MongoDB Mongoose Use Lookup Guide

Image
In This Blog We Will See Complete Guide For Using Joins With Lookup in Mongoose MongoDB Mongoose - Education Funda Simply in MongoDB Mongoose we can use Aggregate Query with $ lookup to get data basis upon JOINS. such as below: await MainModel . aggregate ([ { $match : { "COLUMN_NAME" : value } }, { $lookup : { from : 'relation_collection_name' , localField : 'relation_collection_primary_key' , foreignField : 'this_table_foreign_key' , as : 'ALIASING' } } ]); With above query new column added with ALIASING in which relation collection data will also come. To get data in Object format instead of Array we can use $unwind like below: await MainModel . aggregate ([ { $match : { "COLUMN_NAME" : value } }, { $lookup : { from : 'relation_collection_name' , ...

How To Check MongoDB ID Valid Or Not

Image
As you must aware about the object ID in mongo database or MongoDB is 24 characters long so for check is it valid id or not there is no direct validation method in validations package such as node-input-validator. MongoDB - Education Funda So for checking entered id is valid or not we can us below tech-tics: Approach 1 - Simple JS Validation var checkForHexRegExp = new RegExp("^[0-9a-fA-F]{24}$") checkForHexRegExp.test("i am a string") // false checkForHexRegExp.test("5e63c3a5e4232e4cd0074ac2") // true Approach 2 - With Mongo DB Method (Best Way) var ObjectID = require("mongodb").ObjectID ObjectID.isValid("i am a string") // false ObjectID.isValid("5e63c3a5e4232e4cd0274332") // true With Node Input Validator You Can Use Below Method: const id_exists = "required|string|minLength:24|maxLength:24|idExists"   const validator = require ( "node-input-validator" ) const mongoose = require ( 'mongoose...