Skip to content

Instantly share code, notes, and snippets.

@drobbins
Created March 8, 2012 15:06
Show Gist options
  • Save drobbins/2001409 to your computer and use it in GitHub Desktop.
Save drobbins/2001409 to your computer and use it in GitHub Desktop.
Bug Demo: rdfstore-js
node rdfstoretest.js 
Attempting to create store...

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
TypeError: Cannot read property 'arbiterOnly' of undefined
    at /Users/robbinsd/Dropbox/Repos/rdfstorenode/node_modules/rdfstore/node_modules/mongodb/lib/mongodb/connection/server.js:552:22
    at [object Object].checkoutReader (/Users/robbinsd/Dropbox/Repos/rdfstorenode/node_modules/rdfstore/node_modules/mongodb/lib/mongodb/connection/server.js:569:16)
    at /Users/robbinsd/Dropbox/Repos/rdfstorenode/node_modules/rdfstore/node_modules/mongodb/lib/mongodb/db.js:1249:79
    at Db._executeQueryCommand (/Users/robbinsd/Dropbox/Repos/rdfstorenode/node_modules/rdfstore/node_modules/mongodb/lib/mongodb/db.js:1456:5)
    at Cursor.nextObject (/Users/robbinsd/Dropbox/Repos/rdfstorenode/node_modules/rdfstore/node_modules/mongodb/lib/mongodb/cursor.js:446:13)
    at Array.0 (/Users/robbinsd/Dropbox/Repos/rdfstorenode/node_modules/rdfstore/node_modules/mongodb/lib/mongodb/cursor.js:164:12)
    at EventEmitter._tickCallback (node.js:192:40)
{
"name" : "rdfstore-test",
"version" : "0.0.1",
"dependencies" : {
"rdfstore" : "0.6.x"
}
}
var rdfstore = require("rdfstore");
// Necessary when using cloud services. e.g. Heroku + Mongolab gives a URI
// (process.eng.MONGOLAB_URI) of the form below.
var mongoURL = "mongodb://test:testpass@localhost:27017/myappstore",
parseURL = function parseURL(url){
var urlFragments = url.match(/\/([a-z0-9\.:@_]+):([0-9]+)\/([a-z0-9_]+)$/);
return {
name : urlFragments[3],
host : urlFragments[1],
port : parseInt(urlFragments[2],10) // Port must be an integer, not a string
};
},
parsedURL = parseURL(mongoURL);
console.log("Attempting to create store...");
new rdfstore.Store(
{
persistent:true,
engine:'mongodb',
name: parsedURL.name,
overwrite: true, // delete all the data already present in the MongoDB server
mongoDomain: parsedURL.host, // location of the MongoDB instance, localhost by default
mongoPort: parsedURL.port // port where the MongoDB server is running, 27017 by default
},
function(store){
console.log("Store ready.");
var triples = "<http://example.org/people/David> rdf:type <http://example.org/types/Student> ." +
"<http://example.org/people/David> foaf:name 'David' .";
store.registerDefaultProfileNamespaces();
store.execute("INSERT DATA {"+triples+"}", function(succ, resp){
if (!succ) console.log("Error executing query: ", resp);
else{
store.execute("SELECT * WHERE { ?s ?p ?o . }", function(succ, resp){
if (!succ) console.log("Error executing query: ", resp);
else {
console.dir(resp[0]);
process.exit(1);
}
});
}
});
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment