Skip to content

Instantly share code, notes, and snippets.

View gharriso's full-sized avatar

Guy Harrison gharriso

View GitHub Profile
@gharriso
gharriso / graphlookup.json
Created February 1, 2018 23:26
graphlookup.json
{
"$graphLookup": {
"from": "< name of collection to look up >",
"startWith": "< expression >",
"connectFromField": "< 'from' side of the lookup >",
"connectToField": "< 'to' side of the lookup >",
"as": "< name of field in output document > ",
"maxDepth": "< optional - max recursion level > ",
"depthField": "< optional - recursion depth variable >"
}
{
"$graphLookup": {
"from": "< name of collection to look up >",
"startWith": "< expression >",
"connectFromField": "< 'from' side of the lookup >",
"connectToField": "< 'to' side of the lookup >",
"as": "< name of field in output document > ",
"maxDepth": "< optional - max recursion level > ",
"depthField": "< optional - recursion depth variable >"
}
db.getSiblingDB("GraphTest").socialGraph.findOne();
{
"_id" : ObjectId("5a739cda0c31c5f5afcff87f"),
"person" : 561596,
"name" : "User# 561596",
"friends" : [
94230,
224410,
387968,
406744,
assert: command failed: {
"ok" : 0,
"errmsg" : "$graphLookup reached maximum memory consumption",
"code" : 40099
} : aggregate failed
@gharriso
gharriso / missrate.js
Created June 12, 2018 07:37
Calculate MongoDB wiredTiger Cache miss rate
function missrate(intervalMs) {
var statsStart = db.serverStatus().wiredTiger.cache;
var startTime = new Date();
sleep(intervalMs);
var endTime = new Date();
var statsEnd = db.serverStatus().wiredTiger.cache;
var logicalReads =

Let's have a look at how provenDB operates. You'll need to be somewhat familiar with MongoDB to follow along, since we'll use the mongoDB command shell to demonstrate. If you're not familiar with MongoDB (or even if you are) you might like to look at the MongoDB getting started tutorial.

Create-Read-Update-Delete (CRUD)

You can use normal MongoDB commands to create, read and modify documents. In this example we will use the MongoDB command line shell (available from mongodb.com).

For starters, let's create a few documents:

mongo > db.tutorial.insertMany([{name:"Guy",rating:10},{name:"Mike",rating:9}]);
mongo> db.runCommand({getVersion:1});
{
"ok" : 1,
"response" : "The version is set to: 'current'",
"version" : NumberLong(10206),
"status" : "current"
}
@gharriso
gharriso / provenfiles.sh
Created May 30, 2019 01:22
Shell script to sign, upload and prove files on provendb.com
#
# provenFiles.sh: Store files into a ProvenDB database using `mongofiles`
# optionally sign using a private key
# submit a Blockchain Proof once the files are loaded
#
# Usage: provenFiles.sh -u ProvenDBUri -k keyFile fileSpecification mongoFilesArgs
#
# Author: guy.a.harrison@gmail.com
# License: AGPL
#
//db.adminCommand( { setFeatureCompatibilityVersion: "4.2" } );
use wildcard
db.noIndex.drop();
db.singleIndex.drop();
db.manyIndexes.drop();
db.wildcardIndex.drop();
var i = 0;
var docs = [];
for i := 1; i <= maxId; i++ {
rows, err := db.Query(fmt.Sprintf("SELECT * FROM %s WHERE id=:1", tableName), i)
if err != nil {
fmt.Println(err)
}
rows.Close()
}