db.collection_name_here.find({
"date_field_name_here": {
$gte: new Date(
(
new Date().getTime()
- (30 * 24 * 60 * 60 * 1000)
)
)
},
});
2020-04-26
MongoDB - IF statement using field regex match condition
"field_name_here":
{"$cond": [
{$regexMatch: {
input: "$source_field_name_here",
regex: /string_to_match_here/i
}}
, NumberInt(1) //value if matched
, NumberInt(0) //value if not matched
]},
{"$cond": [
{$regexMatch: {
input: "$source_field_name_here",
regex: /string_to_match_here/i
}}
, NumberInt(1) //value if matched
, NumberInt(0) //value if not matched
]},
2020-04-25
jQuery - Ajax call example
<!DOCTYPE html>
<html>
<head>
<script
src="https://code.jquery.com/jquery-1.12.4.min.js"
integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ="
crossorigin="anonymous"></script>
</head>
<body>
<script>
$.ajax({
url: "https://jsonplaceholder.typicode.com/todos/1",
beforeSend: function(xhr) {
//xhr.setRequestHeader("Authorization", "Basic " + btoa("username:password"));
xhr.setRequestHeader("Content-Type", "application/json")
},
type: "POST",
dataType: "json",
contentType: "application/json",
processData: false,
data: '{"foo":"bar"}',
success: function (response) {
alert(JSON.stringify(response));
},
error: function(){
alert("Error!");
}
});
</script>
</body>
</html>
<html>
<head>
<script
src="https://code.jquery.com/jquery-1.12.4.min.js"
integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ="
crossorigin="anonymous"></script>
</head>
<body>
<script>
$.ajax({
url: "https://jsonplaceholder.typicode.com/todos/1",
beforeSend: function(xhr) {
//xhr.setRequestHeader("Authorization", "Basic " + btoa("username:password"));
xhr.setRequestHeader("Content-Type", "application/json")
},
type: "POST",
dataType: "json",
contentType: "application/json",
processData: false,
data: '{"foo":"bar"}',
success: function (response) {
alert(JSON.stringify(response));
},
error: function(){
alert("Error!");
}
});
</script>
</body>
</html>
2020-04-23
MongoDB - Find documents with _ids of the ObjectId type
db.collection_name.find(
{"_id": {$type: "objectId"}}
);
2020-04-20
Python - How to determine the default/active version on your profile
(1) Command-line method:
python --version
(2) Code method:
import sys
print(sys.version)
python --version
(2) Code method:
import sys
print(sys.version)
2020-04-18
Subscribe to:
Posts (Atom)