This question already has answers here:
How to get the last N records in mongodb?
(16 answers)
Closed 7 years ago.
I can't find the answer. I have a query that can return many answer and I want to get the last one. How to do it?
db.users.find({username: "bob", sort: {createdAt: -1}}).first()
I would like something like this.
do this to get last N records :
function last(N) {
return db.collection.find().skip(db.collection.count() - N);
}
Related
This question already has answers here:
How can I use a regex variable in a query for MongoDB
(7 answers)
Closed 3 years ago.
I've found a similar question and the answer in it didn't turn out to be working for me.
I want to do something like:
ItemModel.find({name: \^VARIABLEHERE\i});
doing a case insensitive search that finds anything that matches the variable.
Also I tried to do something on my own by using:
new RegExp(`/^${variablehere}/`, 'i')
And
new RegExp(`/^${variablehere}/i`)
Yeah I'm new to regular expressions.
All help is appreciated. :)
You can use $regex
ItemModel.find({
name: {
$regex: '.*' + name + '.*', //or you can use `.*${name}.*`
$options: 'i'
}
});
There is a complete manual for variety of regular expression at mongodb $regex manual
This question already has answers here:
Split string into array of characters?
(7 answers)
Closed 3 years ago.
can you help me on this?
I have a simple string:
str="Hello World";
I want to split it as that :
array= str.Split("",System.StringSplitOptions.RemoveEmptyEntries);
result shoud be
array[0]="H"
array[1]="e"
array[2]="l"
array[3]="l"
array[4]="o"
array[5]="W"
array[6]="o"
...
But I don't know to "wildcard" the separator..
Any Idea on this ?
Thanks
?
Just use String.ToCharArray():
SomeArray = str.ToCharArray()
This question already has answers here:
How do I do a "NOT IN" query in Mongo?
(4 answers)
MongoDB not equal to
(6 answers)
Closed 4 years ago.
In Mongoose, if a model M has this field:
list: {type:[String]}
How should I find a document in which a specific value x is not an element of 'list'? I am hoping there is a special operator '$ncontains' so that I can do the following:
M.findOne({list:{$ncontains:x}}...
Use $nin (not in operator):
M.findOne({list: {$nin: ['A']}}
If you $nin array condition contains single element, you can optimize further by using $ne operator:
M.findOne({list: {$ne: 'A'}}
This question already has answers here:
How do I check if a string contains another string in Swift?
(28 answers)
Closed 7 years ago.
The answer in this question: How do I check if a string contains another string in Swift?
No longer works.
var string = "hello Swift"
if string.rangeOfString("Swift") != nil{
println("exists")
}
Will get you:
error: value of type 'String' has no member 'rangeOfString'
What is the new way to do this?
Import Foundation and you will be able to call rangeOfString.
This question already has answers here:
How can I create a UILabel with strikethrough text?
(21 answers)
Closed 8 years ago.
How can I write a string like the following:
H̶̶o̶̶w̶ ̶t̶̶o̶ ̶w̶̶r̶̶i̶̶t̶̶e̶ ̶t̶̶h̶̶i̶̶s̶ ̶t̶̶e̶̶x̶̶t̶
In my app, I need to display the past price of a product that has been replaced by a new price. Like so:
$̶8̶̶0̶̶0̶ -> $600
To get this result you should use NSAttributedString and set the attribute name NSStrikethroughStyleAttributeName. The number used as object for this key defines the style of the line over the text.
self.myLabel.attributedText = [[NSAttributedString alloc] initWithString:#"800" attributes:#{NSStrikethroughStyleAttributeName: #1}];
Cheers