It is possible to drop all databases in influx?
or drop only databases starting with a given prefix?
Something like:
DROP DATABASE somedb*.*
?
Thanks in advance,
It is possible with a short python script:
from influxdb import InfluxDBClient
client = InfluxDBClient(INFLUXDB_ADDRESS,
INFLUXDB_PORT,
INFLUXDB_USER,
INFLUXDB_PASSWORD,
None)
pattern='somedb'
databases = client.get_list_database()
for db in databases:
if db.get('name').startswith(pattern):
client.drop_database(db.get('name'))
Related
I have a list of gene names genes_list and a list of genes that target other genes (list of tuples) genes2, I successfully connected to my local database and created the 20244 nodes labeled GEN with name property.
I am trying to generate a script that automates the creation of relationships for any pair of nodes(usin variables tupla[0]and tupla[1]) in a Neo4j graph but I can't get the for loop to work for a list of tuples, any advice? Im still learning how to use this library any advices would be great! regards!
from py2neo import Node,Relationship,Graph, database,NodeMatcher
import time
import pandas as pd
genes_list=pd.read_csv("Gen_list.txt",delimiter="\t",header=None)
genes_list=genes_list[0].tolist()
for name in genes_list:
graph.run("CREATE(:GEN{name:$name})",name=name)
genes=pd.read_csv(r"C:\Users\espin\OneDrive\Escritorio\MCI\SCRIPTS\dorothea_final.csv", delimiter="\t",header=None)
genes2=list(genes.to_records(index=False))
for tupla in genes2:
existing_u1 = matcher.match("GEN").where(name=tupla[0]).first()
existing_u2 = matcher.match("GEN").where(name=tupla[1).first()
graph.merge(existing_u1,"REGULATES", existing_u2)
I figured out, For the people that want to try this implementation and is using py2neo V4, try using graph.run()
for tupla in genes2:
graph.run("MATCH(a:GEN{name:$name}) MATCH(b:GEN{name:$name1}) CREATE (a)-[:REGULATES]->(b)",name=tupla[0],name1=tupla[1])
remember that the query has to be in the first argument and then you declare the $variables separated by ","
at less this works when you have already created the nodes and does not duplicate the existing ones.
I have two databases in Influxdb:
base1
base2
And metrics like these:
base1.example.allRequests.all.percentiles99 807 1607947555
base2.example.allRequests.all.percentiles99 807 1607947555
I have solution with influx.conf where I'm sending data on different ports.
http://localhost:2003 for base1.....
http://localhost:2004 for base2.....
[[graphite]]
…
bind-address = ":2003”
database = "base-1”
…
[[graphite]]
…
bind-address = ":2004”
database = "base-2”
…
However, I think there is a better solution for this case where data can be sent based on measurement not just using ports. Can someone please help me or suggest how to it?
I am using the below code in Python to try connect to Neo4j. However, when I run the code I get the error: "py2neo.database.status.Forbidden: No write operations are allowed on this database. This is a read only Neo4j instance.".
Does anyone know how I can create a write instance to Neo4j from py2neo?
import py2neo
from py2neo import Node, Relationship
g = py2neo.Graph('bolt://neo4j.het.io:7687', bolt=True)
tx = g.begin()
a = Node("Person", name="Alice")
tx.create(a)
b = Node("Person", name="Bob")
ab = Relationship(a, "KNOWS", b)
tx.create(ab)
tx.commit()
g.exists(ab)
neo4j.het.io:7687 is a public, read only Neo4j instance.
Go to https://neo4j.com/download/ and download your own database, and change your script to hit localhost:7687 instead.
(If you want that specific dataset, it is available for free -> https://github.com/dhimmel/hetionet)
I'm going to preface this that I am a total database pleb. I have 0 experience with any form of databases so I know that I'm in way over my head.
Background: I do Active Directory consulting for my company so I routinely look at client's group membership of their active directory accounts. Currently, I have a PowerShell script that will run my analytics, however, I'm finding that it takes way too long in larger organizations. I'm thinking "There has to be a better way" so I have jumped into looking at databases. NEO4J seems to be a good possible solution as I should be able to to link a user account or group as a member of another group. However, after browsing documentation and forums, I have no idea how to create those links.
I have two CSVs that I have successfully imported with the following information:
Users = DistinguishedName, SAMACCOUNTNAME, MemberOf
Groups = DistinguishedName, SAMACCOUNTNAME, MemberOf, Members
What I want to do is match a string from all users and groups (DistinguishedName) to a string in the group node's property of members. Members is a concatenated string of all DistinguishedName's (whether user or group). So if a node with a DistinguishedName matches part of a string in a group's "members" property, I want to build a one way relationship like so:
user -[memberof] - > group
The best I could rack my brain on this is the following code but I have no idea if I'm even close:
Match(n)
Match(u:user) WHERE n.Members CONTAINS u.DN
Create (u)-[MS:Memberof]->((match)})
In PowerShell, I know how I would accomplish this (loosely translated to relate to the NEO4J world):
$groups = (all-groups)
$AllUsersAndGroups = (all-objs)
foreach ($line in $groups) {
$line.relationship = $line | where {$_.members -contains $AllUsersAndGrups.DistinguishedName}
}
So at last, I'm stuck right now. I will continue to look into it but I figure I would ask the community as you guys have the experience and stuff.
Here is an example of how you should have imported your data (notice that the redundant Members column is not actually needed):
Import (in batches of 5000, to avoid resource issues) each user, and create a unique relationship to its group:
USING PERIODIC COMMIT 5000
LOAD CSV WITH HEADERS FROM "file:///users.csv" AS u
MERGE (u:User {DistinguishedName: u.DistinguishedName, SAMACCOUNTNAME: u.SAMACCOUNTNAME})
MERGE (g:Group {DistinguishedName: u.MemberOf})
MERGE (u)-[:Memberof]->(g);
Import each group, and create a unique relationship to its parent group, if any:
USING PERIODIC COMMIT 5000
LOAD CSV WITH HEADERS FROM "file:///groups.csv" AS g1
MERGE (:Group {DistinguishedName: g1.DistinguishedName, SAMACCOUNTNAME: g1.SAMACCOUNTNAME})
MERGE (g2:Group {DistinguishedName: g1.MemberOf})
MERGE (g1)-[:Memberof]->(g2);
How it's possible to run a collection of query like this (came from a spreadsheet copy) directly in one cypher query? one by one it's ok, but need 100 copy/paste
*******************************
MATCH (c:`alpha`)
where c.name = "a-01"
SET c.CP_PRI=1, c.TO_PRI=1, c.TA_PRI=2
return c ;
MATCH (c:`beta`)
where c.name = "a-02"
SET c.CP_PRI=1, c.TO_PRI=1, c.TA_PRI=0
return c ;
and 100 other lines ...
*********************************
you may try the 'union' clause, which joins the results of queries into one big-honkin result set:
http://docs.neo4j.org/chunked/milestone/query-union.html
That said - the root behavior of what you are trying to do could use some details - maybe there's a better way to write the query - you could use Excel to 'build' the unified query via calculations / macros, you could possibly write a unified query that combines the rules you are trying to follow, there's a lot of options, but it's hard to know a starting direction w/o context....
Talking about the REST API you can use the transactional endpoint in Neo4J 2.0, or the batch endpoint in Neo4J 1.x.
If you want to use the shell, have a look to the import page, in particular the neo4j-shell-tools where they're importing massive quantity of data batching multiple queries.