def run(host=None, db=None, coll=None, source=None, target=None, data="{}", undirected="false"): # Connect to the Mongo collection client = MongoClient(host) db = client[db] graph = db[coll] data = json.loads(data) undirected = json.loads(undirected) rec = { "_id": ObjectId(), "type": "link", "source": ObjectId(source), "target": ObjectId(target), "data": {k: readValue(v) for k, v in data.iteritems()} } if undirected: rec["undirected"] = True graph.insert_one(rec) return bson.json_util.dumps(rec)
def run(host=None, db=None, coll=None, data={}): # Connect to the Mongo collection client = MongoClient(host) db = client[db] graph = db[coll] rec = {"_id": ObjectId(), "type": "node", "data": {k: readValue(v) for k, v in data.iteritems()}} graph.insert_one(rec) return bson.json_util.dumps(rec)
def run(host=None, db=None, coll=None, data={}): # Connect to the Mongo collection client = MongoClient(host) db = client[db] graph = db[coll] rec = { "_id": ObjectId(), "type": "node", "data": {k: readValue(v) for k, v in data.iteritems()} } graph.insert_one(rec) return bson.json_util.dumps(rec)
def run(host=None, db=None, coll=None, source=None, target=None, data="{}", undirected="false"): # Connect to the Mongo collection client = MongoClient(host) db = client[db] graph = db[coll] data = json.loads(data) undirected = json.loads(undirected) rec = {"_id": ObjectId(), "type": "link", "source": ObjectId(source), "target": ObjectId(target), "data": {k: readValue(v) for k, v in data.iteritems()}} if undirected: rec["undirected"] = True graph.insert_one(rec) return bson.json_util.dumps(rec)