Is it possible to do string-replacements in RavenDB javascript-patches? - ravendb

Case: when spawning new dev-environments, I would like to go through some collections and change TLD's in certain string-values, so e.g. "bla bla mydomain.com" becomes "bla bla mydomain.localhost".
I tried simply in patch-window in Raven Studio:
this.MyProperty = this.MyProperty.replace(".com", ".localhost");
But I got:
TypeError: Property 'replace' of object is not a function
After that I went to the docs, where indeed it seems string-replacement is not an option.
My question is: is it possible in any way to do string-replacement in js-patches in RavenDB?

This should just work:
this.Name = this.Name.replace("food", "drink");
I just tested it on http://live-test.ravendb.net/studio/index.html#databases/patch/recentpatch--374082468?&database=Northwind and it does work.
However, make sure that the property actually exists and is of type string.

Ah - found out 5 minutes later:
_.replace(this.MyProperty, ".com", ".localhost");
As docs say, underscore_ references the lodash library (hashtag rtfm)

Related

Replace PHPUnit method `withConsecutive`

As method withConsecutive will be deleted in PHPUnit 10 (in 9.6 it's deprecated) I need to replace all of occurrences of this method to new code.
Try to find some solutions and didn't find any of reasonable solution.
For example, I have a code
$this->personServiceMock->expects($this->exactly(2))
->method('prepare')
->withConsecutive(
[$personFirst, $employeeFirst],
[$personSecond, $employeeSecond],
)
->willReturnOnConsecutiveCalls($personDTO, $personSecondDTO);
To which code should I replace withConsecutive ?
P.S. Documentation on official site still shows how use withConsecutive
I've just upgraded to PHPUnit 10 and faced the same issue. Here's the solution I came to:
$this->personServiceMock
->method('prepare')
->willReturnCallback(fn($person, $employee) =>
match([$person, $employee]) {
[$personFirst, $employeeFirst] => $personDTO,
[$personSecond, $employeeSecond] => $personSecondDTO
}
);
If the mocked method is passed something other than what's expected in the match block, PHP will throw a UnhandledMatchError.
Looks like there are not exists solution from the box.
So, what I found - several solutions
Use your own trait which implements method withConsecutive
Use prophecy or mockery for mocking.

How to call traverseLinkedWorkItems method using Velocity script block?

In the Polarion documentation:
https://almdemo.polarion.com/polarion/sdk/doc/javadoc/com/polarion/alm/tracker/model/IWorkItem.html#traverseLinkedWorkitems(java.util.Set,java.util.Set,java.util.Set,com.polarion.alm.tracker.model.IWorkItem.ITerminalCondition)
I have created empty sets using $objectFactory.newSet() to account for the first 3 parameters, and I have tried "null" for the conditional parameter, but nothing works.
This is an example of what I have tried:
#set($project = "Project X"
#set($workItem1 = 'ABC-123')
#set($emptySet = $objectFactory.newSet())
#set($ts1 = $trackerService.getWorkItem($project,$workItem1))
$ts1 ##output: PObject(WorkItem; subterra:data-service:objects:/default/Project X${WorkItem}ABC-123)
$ts1.traverseLinkedWorkItems($emptySet,$emptySet,$emptySet,'null')
The output is always $ts1.traverseLinkedWorkItems($emptySet,$emptySet,$emptySet,'null')
Is there no way to do this in Velocity? I have seen only one other post regarding this question:
https://community.sw.siemens.com/s/question/0D54O000075P0SCSA0/any-way-to-call-traverselinkedworkitems-from-a-velocity-script-block-widget
Have you tried $null as the last argument? As an undefined reference, it will translate to null.
But this solution will only work if Velocity is not running in strict mode.

Pymongo: insert_many() gives "TypeError: document must be instance of dict" for list of dicts

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.

change field type from rmongodb

I have a collection uploaded to rmongodb. The issue is that all the fields were defined as strings. Thus, my aggregations are not working properly. I've looked through the documentation and it is not clear to me how I would update the field type. I have tried:
mongo.update(mongo, "airRail07",
'{"PAID_FARE_USD":{"$type":2}}',
'{"PAID_FARE_USD":{"$type":1}}')
but, that did not seem to do the trick. Any ideas?
Edit 1
After looking around I've changed the update command as follows:
m1 <- mongo.bson.from.JSON('{"PAID_FARE_USD":{"$type":2}}')
m2 <- mongo.bson.from.JSON('{"$set": {"PAID_FARE_USD":{"$type":1}}}')
mongo.update(mongo, "airRail07", list(m1), list(m2))
This returns TRUE but they $type is not changed.
Thanks,
Carlos
Seems you can't cast types internally - MongoDB: How to change the type of a field?
you can only iteratively update each value.

nHibernate 3.0 queries

Working through the summer of nHibernate tutorials have gotten to the section on queries. Seems there have been changes since that series was made. So I went to the online docs for nHB 3.0 but code such as:
IList cats = session.CreateCriteria(typeof(Cat))
.Add(Expression.Like("Name", "Fritz%"))
.Add(Expression.Between("Weight", minWeight, maxWeight))
.List();
Generates the error "The name 'Expression' does not exist in the current context"
Code like:
return session.CreateCriteria(typeof(DataTransfer.Customer))
.Add(new NHibernate.Criterion.LikeExpression("Firstname", firstname))
.Add(new NHibernate.Criterion.LikeExpression("Lastname", lastname))
.List<Customer>();
Works but it seems that it is missing a number of query methods like GtExpression.
Are the online docs up to date, and if so, why can't I use Expression...
If the online docs aren't up to date then where do I get a description of the Criterion interface?
Thanks
You forgot to add using NHibernate.Criterion;.
Anyway, the Expression class is deprecated. Use Restrictions instead.
Weird thing. I still use Expression.* static methods and these are still work. Are you sure you use the latest version of NH3.0? I use Alpha 2 version.
If you need to make it work urgently, let's try the QueryOver<> feature:
return session.QueryOver<DataTransfer.Customer>()
.WhereRestrictionOn(u => u.Name).IsLike("Fritz%")
.AndRestrictionOn(u => u.Weight).IsBetween(minWeight).And(maxWeight)
.List();
It works well for simple queries