I have a RavenDB Index that I am using to delete a bunch of documents at one time. I would like to know home many documents were actually deleted after the operation is done, however I can't figure out how to get that information from a DatabaseCommands call. For a RavenQuery/DocumentQuery you can use the out Statistics, but I haven't found anything for the DatabaseCommands.
I did find a RetrieveDetails flag as part of the BulkOperationsOptions but I'm not sure how to actually see the details. Here is what my query looks like
var op = connection.Store.DatabaseCommands.DeleteByIndex(
"Store/ByExpiration",
new IndexQuery
{
Query = "Expiration:yes"
},
new BulkOperationOptions
{
AllowStale = false,
RetrieveDetails = true
});
op.WaitForCompletion();
At this point I am not sure how to get the details once the operation has completed. Has anyone else figured out how to get these details?
The result is returned as a RavenJToken in WaitForCompletion.
var result = op.WaitForCompletion();
The documentation isn't clear on this.
Hint: When I can't find examples in the documentation I look at the RavenDB source code unit tests for examples, e.g. the ShouldRetrieveOperationDetailsWhenTheyWereRequested unit test.
Related
I haven't been able to find any relevant solutions to my problem when googling, so I thought I'd try here.
I have a program where I parse though folders for a certain kind of trace files, and then save these in a MongoDB database. Like so:
posts = function(source_path)
client = pymongo.MongoClient()
db = client.database
collection = db.collection
insert = collection.insert_many(posts)
def function(...):
....
post = parse(trace)
posts.append(post)
return posts
def parse(...):
....
post = {'Thing1': thing,
'Thing2': other_thing,
etc}
return post
However, when I get to "insert = collection.insert_many(posts)", it returns an error:
TypeError: document must be an instance of dict, bson.son.SON, bson.raw_bson.RawBSONDocument, or a type that inherits from collections.MutableMapping
According to the debugger, "posts" is a list of about 1000 dicts, which should be vaild input according to all of my research. If I construct a smaller list of dicts and insert_many(), it works flawlessly.
Does anyone know what the issue may be?
Some more debugging revealed the issue to be that the "parse" function sometimes returned None rather than a dict. Easily fixed.
I'm triying to retrieve a ClassDescription symbolicName of an IDocument object. It seems that i have to fetch its ClassDescription even if I just want the symbolicName.
Is there a way to do it ? I just want to avoid doing a fetch for every browsed document...
(Also IDocument.GetClassName doesn't help, it returns "Document")
I finally found a way, by making an SQL SELECT request retrieving the classDescription ID (which is not the symbolicName ID, but rather an "internal" one) :
Select This, d.Id, d.ClassDescription
From Document d
where d.Id = ID
It seems to be lighter than a line like document.fetch(classDescription) (pseudo call) cause it should just retrieves the ID.
I thought it worth mentioning a problem regarding the accepted answer.
There are times that doing a query would be "lighter" however I believe you are missing something involving fetching a document.
FileNet's fetchInstance command can take in a PropertyFilter.
In your case you could do something along the lines of:
PropertyFilter pf = new PropertyFilter();
pf.AddIncludeProperty(new FilterElement(null, null, null, "ClassDescription", null));
doc = Factory.Document.FetchInstance(os, new Id("doc.ID()"), pf);
You would probably want to look at your original fetch of this document and make sure to specify the full list of property filters at that point.
See Working With Documents
I found and have used a closure that temporarily turns hibernate.SQL logging to Trace to allow me to see the exact queries that are generated. However I would like to be able to have PostgresQL's explain run automatically instead of having to pull out queries individually for analysis.
logging closure:
(found here: http://www.intelligrape.com/blog/2011/10/21/log-sql-in-grails-for-a-piece-of-code/)
public static def execute(Closure closure) {
Logger sqlLogger = Logger.getLogger("org.hibernate.SQL");
Logger transactionLogger = Logger.getLogger("org.hibernate.transaction");
Level currentLevel = sqlLogger.level
Level transLevel = transactionLogger.level
sqlLogger.setLevel(Level.TRACE)
transactionLogger.setLevel(Level.TRACE)
def result = closure.call()
sqlLogger.setLevel(currentLevel)
transactionLogger.setLevel(transLevel)
result
}
usage:
def result
execute{
result=Dog.createCriteria().list{
eq("breed","Greyhound")
}
}
I would like something that can be used in a similar way.
Is this something I could do with a sub-class of Criteria or Hibernate.Restrictions ?
Or is there something I'm missing in the docs on how to modify the SQL statement that is sent to the DB from GORM?
Thanks for any info.
Assuming you don't want all queries, but only the longer-running ones you might find the "auto explain" add-on for PostgreSQL useful.
http://www.postgresql.org/docs/9.1/static/auto-explain.html
I was wondering how I would go about checking to see if a table contains a value in a certain column.
I need to check if the column 'e-mail' contains an e-mail someone is trying to register with, and if something exists, do nothing, however, if nothing exists, insert the data into the database.
All I need to do is check if the e-mail column contains the value the user is registering with.
I'm using the RedBeanPHP ORM, I can do this without using it but I need to use that for program guidelines.
I've tried finding them but if they don't exist it returns an error within the redbean PHP file. Here's the error:Fatal error: Call to a member function find() on a non-object in /home/aeterna/www/user/rb.php on line 2433
Here's the code that I'm using when trying this:
function searchDatabase($email) {
return R::findOne('users', 'email LIKE "' . $email . '"');
}
My approach on the function would be
function searchDatabase($email) {
$data = array('email' => $email);
$user = R::findOne('users', 'email LIKE :email, $data);
if (!empty($user)) {
// do stuff here
} // end if
} // end function
It's a bit more clean and in your function
Seems like you are not connected to a database.
Have you done R::setup() before R::find()?
RedBeanPHP raises this error if it can't find the R::$redbean instance, the facade static functions just route calls to the $redbean object (to hide all object oriented fuzzyness for people who dont like that sort of thing).
However you need to bootstrap the facade using R::setup(). Normally you can start using RB with just two lines:
require('rb.php'); //cant make this any simpler :(
R::setup(); //this could be done in rb.php but people would not like that ;)
//and then go...
R::find( ... );
I recommend to check whether the $redbean object is available or whether for some reason the code flow has skipped the R::setup() boostrap method.
Edited to account for your updated question:
According to the error message, the error is happening inside the function find() in rb.php on line 2433. I'm guessing that rb.php is the RedBean package.
Make sure you've included rb.php in your script and set up your database, according to the instructions in the RedBean Manual.
As a starting point, look at what it's trying to do on line 2433 in rb.php. It appears to be calling a method on an invalid object. Figure out where that object is being created and why it's invalid. Maybe the find function was supplied with bad parameters.
Feel free to update your question by pasting the entirety of the find() function in rb.php and please indicate which line is 2433. If the function is too lengthy, you can paste it on a site like pastebin.com and link to it from here.
Your error sounds like you haven't done R::setup() yet.
My approach to performing the check you want would be something like this:
$count = count(R::find('users', 'email LIKE :email', array(':email' => $email)));
if($count === 0)
{
$user = R::dispense('users');
$user->name = $name;
$user->email = $email;
$user->dob = $dob;
R::store($user);
}
I don't know if it is this basic or not, but with SQL (using PHP for variables), a query could look like
$lookup = 'customerID';
$result = mysql_fetch_array(mysql_query("SELECT columnName IN tableName WHERE id='".$lookup."' LIMIT 1"));
$exists = is_null($result['columnName'])?false:true;
If you're just trying to find a single value in a database, you should always limit your result to 1, that way, if it is found in the first record, your query will stop.
Hope this helps
For some reason I can't find a document when I search by the id of a nested document. I can perform other finds easily enough so these two work:
User.findOne({"_id" : some_id}, function(err,user){}
User.findOne({"arrayOfNestedDocs.value":someValue}, function(err,user){}
But finding by id of nested doc doesn't work:
User.findOne({"arrayOfNestedDocs._id" : some_id}, function(err,user){}
I can perform the search in a mongo shell so but not via mongoose. Any ideas would be helpful.
I've added it as an issue in the project
If you're trying to find an embedded document then the syntax is:
User.findOne({_id: id}, function(err, user) {
var embeddedDoc = user.embeddedDocs.id('embeddedDocId');
});