0.1.7 • Published 1 year ago

krakenmongo v0.1.7

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

KrMongo - Driver to contect Thing to mongoDB

This driver contains functions to help connecting things to mongoDB.

Main methods:

  • get
  • search
  • post
  • delete
  • deleteAll
  • getCollections

Running tests

node --experimental-vm-modules node_modules/.bin/jest

Publish

npm adduser
npx parcel build
npm publish

Setup

Set mongoDb login parameters

Through environement variables

process.env.dbAppName = "APP_NAME"
process.env.dbUrl = "mongodb.net" 
process.env.dbName = "DB_NAME";
process.env.dbUserid = "USER_ID"
process.env.dbPassword = "PASSWORD";
process.env.dbCollection = "COLLECTION_NAME";

Directly to the KrMongo object

let k = new KrMongo()

k.dbAppName = "APP_NAME"
k.dbUrl = "mongodb.net" 
k.dbName = "DB_NAME";
k.dbUserid = "USER_ID"
k.dbPassword = "PASSWORD";
k.collection = "COLLECTION_NAME"

How to use

Get

let k = new KrMongo()

let t = new KrThing("Thing", "Thing1")
let action = await k.get(t)                    // Returns action thing 
if(action.a.isSuccess() == false){ throw(action.a.error) }
let result = action.p.get('result').value      // Requested thing
console.log(result.record)

Search

let k = new KrMongo()

let limit = 10
let offset = 0
let orderBy = "name"
let orderDirection = -1

let action = await k.search({"@type": "Thing"}, limit, offset, orderBy, orderDirection) 
if(action.a.isSuccess() == false){ throw(action.a.error) }
let results = action.p.get('result').values      // Requested thing
console.log(results.length)

Post

let k = new KrMongo()

ler record = {
	"@context": "https://schema.org/",
	"@type": "Thing",
	"@id": "thing1",
	"name": "thing1"
}
let t = new KrThing(record)

let action = await k.post(t)                    // Returns action thing 
if(action.a.isSuccess() == false){ throw(action.a.error) }

Delete

let k = new KrMongo()

let t = new KrThing("Thing", "Thing1")
let action = await k.delete(t)                    // Returns action thing 
if(action.a.isSuccess() == false){ throw(action.a.error) }

DeleteAll

let k = new KrMongo()

let t = new KrThing("Thing", "Thing1")
let action = await k.deleteAll()                    // Returns action thing 
if(action.a.isSuccess() == false){ throw(action.a.error) }
0.0.10

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.0.9

1 year ago

0.1.7

1 year ago

0.0.8

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.6

1 year ago

0.0.7

1 year ago

0.1.5

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago