I would like to do a negative xpath query like this:
$xpath->query(//a[DoesNotContain(#class,'some_class')]);
I know about this
$xpath->query(//a[contains(#class,'some_class')]);
$xpath->query(//a[not(contains(#class, 'some_class'))]);
Related
Basically what I am trying to do is say to my query that I want all of the users that have isBoosted = True to be first and after that, all others.
Thank You!
you can use the method sort to order descending because true=1 and false=0 like this:
db.users.find().sort("isBoosted", -1)
Or
db.users.find([your filter criteria]).sort("isBoosted", -1)
i wrote the following filter in the mongodb console
"outers":{"$elemMatch":{"$elemMatch":{y:{$gt : 48.99}}}}
what would be the bson equivalent? i got this:
elemMatch("outers", elemMatch("y", gt("y", 48.99)))
but it feels wrong, because of the duplicate y-variable
I think this should work:
Filters.elemMatch("outers", Filters.lt("y", 48.99))
elemMatch("outers", eq("$elemMatch", lt("y", 48.99)))
did the trick
I have 1 issue with mongodb query search with exact values. i want to get collections irrespective of case sensitive. for this i found some querys like below. its working fine.
db.applications.find({"blocks.HOSPITAL_INFO.data.name": new RegExp('^VIKRAM$', 'i')});
in laravel i am using jessengers. . above query i can write as raw query in laravel.
but my issue is when ever i am using $In:{'a','b'} like this how can i write regex for this. FYI 'a','b' are dynamic array values. so how can i write regex for these array values?
The query in MongoDB would be something like this:
db.applications.find({"blocks.HOSPITAL_INFO.data.name":
{$in:[new RegExp('^a$', 'i'),new RegExp('^b$', 'i')]}});
OR, alternatively:
db.applications.find({"blocks.HOSPITAL_INFO.data.name":
{$in:[/^a$/i,/^b$/i]}});
...where a & b are your dynamic variables.
I'm not very familiar with Laravel, but I'm guessing it would look something like this:
$applications = Application::whereIn('blocks.HOSPITAL_INFO.data.name',
[new MongoRegex('^a$/i'), new MongoRegex('^b$/i')])->get();
I want use mongoid search like query with integer column.
I know use mongodb can use below command to query
db.test.find({ $where: "/^123.*/.test(this.example)" })
How write it with mongoid?
You know you can use all the usual MongoDB query operators with Mongoid's where so:
Test.where(:$where => '/^123/.test(this.example)')
If you look at the Mongoid::Criteria that that where gives you, you'll see something like this:
=> #<Mongoid::Criteria
selector: {"$where"=>"/^123/.test(this.example)"}
options: {}
class: Test
embedded: false>
and there's the underlying MongoDB query in selector.
BTW, that .* didn't do anything useful in your regex so I took it out.
I want to write something of the sort:
//a[not contains(#id, 'xx')]
(meaning all the links that there 'id' attribute doesn't contain the string 'xx')
I can't find the right syntax.
not() is a function in XPath (as opposed to an operator), so
//a[not(contains(#id, 'xx'))]
you can use not(expression) function
or
expression != true()
None of these answers worked for me for python. I solved by this
a[not(#id='XX')]
Also you can use or condition in your xpath by | operator. Such as
a[not(#id='XX')]|a[not(#class='YY')]
Sometimes we want element which has no class. So you can do like
a[not(#class)]
Use boolean function like below:
//a[(contains(#id, 'xx'))=false]