New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

mongr

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongr

graph database on top mongodb

latest
Source
npmnpm
Version
0.0.1
Version published
Weekly downloads
2
-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

Mongr

Mongr is graph database built on the document-stored MongoDB and its for Node.js. Mongr using subj-pred-obj triplestores for storing graph data.

example data

{
	subj : 'ali',
	pred : 'follow',
	obj : 'buddy'
}

Install

on Node.js

npm install mongr --save

Usage

Initializing database

var mongr = require('mongr')

var db = mongr('your/mongodb/url/', 'graph-name')
// example
// var db = mongr('mongodb://localhost:27017/graphdb', 'mongr')

Insert

Data which inserted is must be an Array. Insert single or multiple data.

var insertData = [{
	subj : 'ali',
	pred : 'follow',
	obj : 'ando'
}, {
	subj : 'ando',
	pred : 'follow',
	obj : 'eddy'
}]

db.insert(insertData, function(err, result) {
	// do something when inserting done
})

Properties

Triplestore can also adding with properties.

var insertData = [{
	subj : 'ali',
	pred : 'follow',
	obj : 'ando',
	time : new Date(),
	cost : 10
}]

db.insert(insertData, function(err, result) {
	// do something when inserting done
})

Searching graph data. Data must be array.

(subj) -: (pred) -> (obj)

example data

a -: follow -> b
a -: follow -> c
b -: follow -> c
b -: follow -> a
c -: follow -> d

Search who a follows.

var searchData = [{
	subj : 'a',
	pred : 'follow',
	obj : '$following'
}]

db.search(searchData, function(err, result) {
	console.log(result)
	// result is something like this
	// {
	// 	following: ['b', 'c'],
	//	value: [ {...} ]
	// }
})

Another example, Search who a follows and following back to 'a'.

var searchData = [{
	subj : 'a',
	pred : 'follow',
	obj : '$following'
}, {
	subj : '$following',
	pred : 'follow',
	obj : 'a'
}]

db.search(searchData, function(err, result) {
	console.log(result)
	// result is something like this
	// {
	// 	following: ['b'],
	//	value: [ {...} ]
	// }
})

Another example, Search who a follows and not following back to a.

var searchData = [{
	subj : 'a',
	pred : 'follow',
	obj : '!$notFolBack'
}, {
	subj : '!$notFolBack',
	pred : 'follow',
	obj : 'a'
}]

db.search(searchData, function(err, result) {
	console.log(result)
	// result is something like this
	// {
	// 	notFolBack: ['c'],
	//	value: [ {...} ]
	// }
})

Another example, Search follow of follow from a.

var searchData = [{
	subj : 'a',
	pred : 'follow',
	obj : '$following'
}, {
	subj : '$following',
	pred : 'follow',
	obj : '$followOfFollow'
}]

db.search(searchData, function(err, result) {
	console.log(result)
	// result is something like this
	// {
	// 	following: ['b', 'c'],
	// 	followOfFollow: ['a', 'b', 'c', 'd'],
	//	value: [ {...} ]
	// }
})

Update

Updating multiple data.

db.update(
	{
		pred : 'follow'
	},
	{
		pred : 'flw'
	},
	function(err, rowAffected) {
	// do something when updating done
	}
)

Delete

Deleting

db.delete({
		pred : 'follow'
	}, function(err, rowAffected) {
		// do something when updating done
})

Keywords

mongo

FAQs

Package last updated on 06 May 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts