How can I do it?
query.exists("year");
query.lessThanOrEqualTo("year", toYear);
query.greaterThanOrEqualTo("year", fromYear);
When the code is like above I get an error - I think it is because I have blank filed "year".
How can I do the Constraints on the "year" filed only if the "exists" is true?
thanks
simply use two queries..
//1st query
query.exists("year");
query.find{
success:{
//2nd query
query.lessThanOrEqualTo("year", toYear);
query.greaterThanOrEqualTo("year", fromYear);
query.find{
success:{
//desired result
}
}
}error:{
//"year does not exists";
}
Related
Hi im getting a unidentifiable error from postgres. Would anyone be able to lead me towards to right solution?
'SELECT * FROM photo'+
' JOIN collection ON (photo.collection_id = collection.id)'+
' JOIN photographer ON (photo.photographer_id = photographer.id)'+
` WHERE collection.title = ${category} AND to_tsvector(photo.decription||' '||photographer.name ||' '||photographer.location||' '||photographer.bio||' '||photographer.name||' '|| photographer.twitter_username||' '||photographer.instagram_username) ## to_tsquery(${text})`,
the error reads
error: column "undefined" does not exist
I am assuming that the select you try to run is from node.js.
In that case,
check if variables 'category' and 'text' are initialized with real value,
it seems to me that one of them is 'undefined'
watch out for condition collection.title = ${category} - category is probable string, in that case, quotes are missing, so it should be:
collection.title = '${category}'
the same problem may appear with 'text' too, to_tsquery(${text})
changes to to_tsquery('${text}')
I believe in your JS code you have a problematic variable value. So the variable returns undefined which is directly and unescaped put into the query. The query interprets the text undefined as column name which is, naturally, not existing.
My guess: Check the category and text variables in your JS code.
whoever from the future if you have to deal with this
'SELECT * FROM photo'+
' JOIN collection ON (photo.collection_id = collection.id)'+
' JOIN photographer ON (photo.photographer_id = photographer.id)'+
` WHERE collection.title = ${category}`+
` AND to_tsvector(CONCAT(photo.description, '' ,photographer.name, '' ,photographer.location, '' ,photographer.bio, '' ,photographer.name, '' ,photographer.twitter_username, '' ,photographer.instagram_username)) ## to_tsquery(${req.body.searchBody})`
Thanks for the help guys
I have a collection like this;
{
"_id" : ObjectId("5d428c8b0edc602c155929c5"),
"source" : "connection",
"class" : "dns",
"ts" : 1503528301.909886,
"uid" : "C8avTr2cLyrJJxkN9",
}
If I print the key and type of key in mongo shell, I can see that ts actually is a string:
ts string
When I receive a query, I need to get the ts value from the URL and do a .find() query.
GET http://localhost:3300/alerts?ts=1503528332.909886&limit=100&page=1
startTs = req.query.ts
This may have to be converted to a ts without the '.' after the second. I have looked at converting 1503528332.909886 to float, multiply by 1000 1503528332909.886 and truncate to integer 1503528332909. I have also tried using both string and number format.
results.results = await model
.find({"ts": {"$gte": <ts_variable: what format do I use?> }})
.skip(startIndex)
.exec();
res.paginatedResults = results;
If I only use ".find({})" and not try to select based on ts, everything works as expected. Appreciate any tips you have.
I have the following function which acts on an AJAX query:
var formData = $(this).serialize(); //put the form names and values into an array called formdata
$.get('filtertest.php',formData,processData); //jquery ajax call
function processData(data){
if(data =="a"){
$('#content').html("<h2>You have not selected any 'types of dwelling'. Please select at least one.</h2>");
$('#linky').hide();
}
else if(data=="b"){
$('#content').html("<h2>You have not selected any 'style of dwelling'. Please select at least one.</h2>");
$('#linky').hide();
}
else if(data=="c"){
$('#content').html("<h2>You have not selected any 'situation of dwelling'. Please select at least one.</h2>");
$('#linky').hide();
}
else if(data==1){
$('#content').html('<h2>There is ' + data + ' property available!</h2>');
$('#linky').show();
}
else if(data==0){
$('#content').html('<h2>There are no properties available, please expand your search options.</h2>');
$('#linky').hide();
}
else{
$('#content').html('<h2>There are ' + data + ' properties available!</h2>');
$('#linky').show();
}
}//end processData
In the filtertest.php file, the following code is used to check if none of the field values are entered, and if so returns the letter a:
//if none of the TODs are selected, returns an error
if ($_GET[tod_house]==0 && $_GET[tod_bung]==0 && $_GET[tod_flat]==0 && $_GET[tod_barnc]==0 && $_GET[tod_farm]==0 && $_GET[tod_small]==0 && $_GET[tod_build]==0 && $_GET[tod_devland]==0 && $_GET[tod_farmland]==0 ){
echo "a";
return;
}
However in the initial ajax function processData the line beginningif(data =="a"){ isnt catching the value echoed - its going all the way down to the final else function. The strange thing is the letter 'a' is input into the html in this final else function, meaning the echo is correct and the filtertest.php file is returning immediatly - its just not being caught by the if function testing for the letter 'a'.
There must be some syntax error here but Ive been looking at it for the last hour trying different things and I cant work it out, its starting to really annoy me!!
edit
After changing the daft error pointed out below, it still wasnt working. I tried echoing a different number instead of a letter. I changed 'a' in both processData and filtertest.php to '-1' and HEY PRESTO! it works. So it is an error with the string containing 'a' - am I getting the comparison of two strings wrong in the javascript function?
The problem is how you try to access your data in the $_GET array: keys should be strings, i.e.
$_GET['tod_house']
not
$_GET[tod_house]
More precision coming from Marc B' comment: the output won't be just a and thus won't be picked.
I have a table listing values pulled from a database, I then gather up these values and save them into an array to be sent back to the database (with JSON) I'm using
$('#ing_table tr').each(function(row, tr){
ingredients[row] = {
"ing" : $(tr).find('input:eq(0)').val(),
"amt" : $(tr).find('input:eq(1)').val(),
"meas" : $(tr).find('option:selected').text()
};
});
to get this info. Generally everything works great except that a few of the strings that occasionally populate the 'ing' row have quotes (") which mess things up. I tried this:
$('#ing_table tr').each(function(row, tr){
ingredients[row] = {
"ing" : $(tr).find('input:eq(0)').val().replace('"', ' '),
"amt" : $(tr).find('input:eq(1)').val(),
"meas" : $(tr).find('option:selected').text()
};
});
but I get a 'cannot call method 'replace' of undefined'
Note: The above code is found in the function stroreIng() which returns ingredients. I used:
var recIng = storeIng();
recIng = $.toJSON(recIng);
this is where it added \\ before the " in the JSON
Any help would be appreciated
It seems that there simply isn't any input present for some rows. And in case of empty selectors val() returns undefined:
$().val() == undefined //true
so your replace method fails in such cases. You should use something like this:
$('#ing_table tr').each(function(row, tr){
ingredients[row] = {
"ing" : ($(tr).find('input:eq(0)').val() || "").replace('"', ' '),
"amt" : $(tr).find('input:eq(1)').val(),
"meas" : $(tr).find('option:selected').text()
};
});
I was unable to get the replace() method to work here, but I went to the php page and was able to use str_replace() to remove the escaped quote. Now everything works fine. Thanks for your help!
Hey all im not every good with regexp i was hoping someone could help.
ok so this is the sting "KEY FOUND! [ 57:09:91:40:32:11:00:77:16:80:34:40:91 ]"
And i need to pull "57:09:91:40:32:11:00:77:16:80:34:40:91", now this key can be meany length not just as written here and with or with out the ":"
now the second sting i would like to test and extract is: "[00:00:09] Tested 853 keys (got 179387 IVs)", i would like to pull "00:00:09" and "853" and "179387".
this would be the raw string http://regexr.com?31pcu or http://pastebin.com/eRbnwqn7
this is what im doing now.
var pass = new RegExp('KEY FOUND\!')
var tested = new RegExp('Tested')
var fail = new RegExp('\Failed. Next try with ([0-9]+) IVs')
var data="Look at the link i added"
if (tested.test(data)) {
self.emit('update', mac, {
'keys' : data.split('Tested ')[1].split(' keys ')[0],
'ivs' : data.split('got ')[1].split(' IVs')[0]
});
} else if (pass.test(data)) {
var key = data.split('KEY FOUND! [')[1].split(' ]')[0].split(':').join('');
} else if (fail.test(data)) {
console.log(data);
}
thanks all
Edit:
I have added more the the question to help with the answer
If it is always surrounded by [] then it is simple:
\[([\s\S]*)\]
This will match any characters enclosed by [].
See it in action here.