Riak ruby client trying to delete CRDT map - ruby

using ruby client (2.3.0) with Riak 2.0. I've created a CRDT bucket type of 'Maps', which store (surprise) maps.
Everything works including search, etc. but for the life of me I can't work out how to delete a map when I no longer need it.
I've tried this based on things I found:
robject = #bucket.get #key, type: 'maps'
robject.delete
This does not give an error, but the map is not removed from Riak; neither is it 'tombstoned' as I can still retrieve the data from it and the search index still has the data too.
I've also tried:
#bucket.delete #key, 'maps'
but this doesn't work either. It gives error "no implicit conversion of Symbol into Integer" and without 'maps' it doesn't work either.
Looking at the first option in the console, it looks to me it is accessing the correct object, but calling 'delete' on it seems to have no effect.
How do I correctly delete the map? At least if I can have it removed from indexing results would be a big step!
Thanks

d'oh, didn't read the docs correctly.
it's simply:
#bucket.delete #key, type: 'maps'
I missed the 'type:'
Silly

Related

How do I get the "true" root cause of an error in Elasticsearch.NET / NEST?

I'm doing some custom error handling/logging with Elasticsearch in a .NET environment using Elasticsearch.NET. Given an IResponse object, I'm trying to arrive at the best strategy for plucking out a short, succinct, and useful "root cause" message. I originally arrived at this, which works great when we come across indexing errors specifically:
shortMsg = response.ServerError?.Error?.RootCause?.FirstOrDefault()?.Reason;
But I recently ran into a query-time error where the above gave me this:
"failed to create query: { ... }"
(Details left out, but it effectively dumped the entire query.)
Since that isn't particularly useful, I spent a little time traversing the response to see what else is available. response.ServerError.Error.Reason, for example, returns "all shards failed" - also not particularly useful. response.DebugInformation is much bigger than what I'd like for this particular purpose, but I did find the needle in the haystack I was looking for toward end of it:
"Can't parse boolean value [True], expected [true] or [false]"
That's perfect, and to avoid parsing it out of DebugInfomation I also managed to find it here:
response.ServerError.Error.Metadata.FailedShards.First().Reason.CausedBy.Reason
So at this point I've arrived at this strategy to get my shortMsg:
shortMsg =
response.ServerError?.Error?.Metadata?.FailedShards?.FirstOrDefault()?.Reason?.CausedBy?.Reason ??
response.ServerError?.Error?.RootCause?.FirstOrDefault()?.Reason;
My concern with this is that it might be naive to assume that if something exists along the first path, it'll always be "better" than the second. A better understanding of the response structure itself might be key to arriving at the best strategy here.
Any suggestions on improving this?

Get Github Issue based only on title

I need to modify the body of an existing GitHub issue in a Project. All I'll be passed is the title of the issue, and a word (the word exists in the body, and I'll just need to fill the checkbox next it).
It looks like to do this I'll need to use the GET API to get the body of the issue, modify it, and then use the EDIT API to swap in the new body. However the GET API can only be called with the issue number. I need to do all this as quickly as possible. Is there some way to search via an API call?
Thoughts much appreciated!
Edit: All my issues are in the same project (and issue titles will be unique there). I've also recently discovered Github's GraphQL API, which may be applicable here.
You can use the issue search endpoint with the in and repo¹ keywords:
GET /search/issues?q=text+to+search+in:title+repo:some/repo
Of course, issue titles aren't guaranteed to be unique. You'll have to request each of the issues that comes back and see if its body contains the word you're looking for. Even in that case you could get multiple positive results.
It would be much better if you could search by issue number.
¹I've assumed that you really mean "repository" when you say "project". But if you're actually talking about GitHub Project Boards you can use the project keyword as well or instead.

Performing MongoDB's cursor.forEach() in ruby

I've just started experimenting with Ruby's Sinatra a couple of days ago, I'm trying to query a MongoDB, the find_one() method works very well, but when trying to get more than one document (i.e when using find()) a cursor is returned, I'm used to using the cursor.forEach() method to iterate through all the returned documents, but as I am new to ruby, I am having a hard time figuring it out.
Would be great if you can point me in the right direction, also if you know of a Mongo/Ruby command dictionary or cheat sheet, I would really appreciate it.
Some code to help with the matter:
#The following code is intentionally formatted the way it is, (i.e the case
#insensitive, the way I'm calling the database), all that is irrelevant,
#but there to show you what I'm doing; I might be screwing up somewhere.
#works fine, returns JSON of required document
settings.mongo_db['col'].find_one({"key" => /#{value}/i}).to_json
#returns cursor, need to iterate
settings.mongo_db['col'].find({"key" => /#{value}/i}).to_json
Your replies/thoughts are much appreciated.
Well generally in ruby in order to iterate you just use .each but since you just want to return your cursor results as JSON just turn the statement around
JSON.generate( settings.mongo_db['col'].find({"key" => /#{value}/i}).to_a )
So that should serialize as an array of documents.
Also see other methods in the JSON package.

What's the difference in calling ThinkingSphinx.search and ModelName.search...?

I have started using ThinkingSphinx for text search but can anybody explain me what's the difference between these two way of calling thinkingsphinx search , though I see both returns the same result and working fine in my local system. But does it effect in some other environment like production.??
From the documentation of Thinking Sphinx:
You can use all the same syntax to search across all indexed models in
your application:
ThinkingSphinx.search 'pancakes'
So if you call search on ThinkingSphinx, it searches in all of your indexed models.

MongoDB find and remove - the fastest way

I have a quick question, what is the fast way to grab and delete an object from a mongo collection. Here is the code, I have currently:
$cursor = $coll->find()->sort(array('created' => 1))->limit(1);
$obj = $cursor->getNext();
$coll->remove(array('name' => $obj['name']));
as you can see above it grabs one document from the database and deletes it (so it isn't processed again). However fast this may be, I need it to perform faster. The challenge is that we have multiple processes doing this and processing what they have found BUT sometimes two or more of the processes grab the same document therefore making duplicates. Basically I need to make it so a document can only be grabbed once. So any ideas would be much appreciated.
Peter,
It's hard to say what the best solution is here without understanding all the context - but one approach which you could use is findAndModify. This will query for a single document and return it, and also apply an update to it.
You could use this to find a document to process and simultaneously modify a "status" field to mark it as being processed, so that other workers can recognize it as such and ignore it.
There is an example here that may be useful:
http://docs.mongodb.org/manual/reference/command/findAndModify/
Use the findAndRemove function as documented here:
http://api.mongodb.org/java/current/com/mongodb/DBCollection.html
The findAndRemove function retrieve and object from the mongo database and delete it in a single (atomic) operation.
findAndRemove(query, sort[, options], callback)
The query object is used to retrieve the object from the database (see collection.find())
The sort parameter is used to sort the results (in case many where found)
I make a new answer to remark the fact:
As commented by #peterscodeproblems in the accepted answer. The native way to this in mongodb right now is to use the
findAndModify(query=<document>, remove=True)
As pointed out by the documentation.
As it is native, and atomic, I expect this to be the faster way to do this.
I am new to mongodb and not entirely sure what your query is trying to do, but here is how I would do it
# suppose database is staging
# suppose collection is data
use staging
db.data.remove(<your_query_criteria>)
where is a map and can contain any search criteria you want
Not sure if this would help you.

Resources