How to Filter the Running Nodes

How to filter object from one key only and return it as json?

If you are using mongoose you can use Query.prototype.select() function to filter the properties:

router.get("/", isLoggedIn, (req, res, next) => {
User.findById(req.user._id).select("-password") //--> prefixing a path with - will flag that path as excluded
.then((user) => {
res.status(200).json(user);
})
.catch((err) => {
console.log(err);
res.status(500).json({ errorMessage: err.message });
});
})

filtered by name using node js

You can use String.protytype.endsWith function to compare the strings with your extension

const file = 
[ "animal_bio.txt",
"xray.pdf",
"fish_bio.txt",
"mammal_doc.txt",
"human_bio.txt",
"machine.jpg"
]
result = file.filter((fileName) => fileName.endsWith("_bio.txt"));
console.log(result)

nodejs filtering an array of objects where the filtering is partially done in an async function

I didn't inspect your attempts that closely, but I believe you are experiencing some race conditions (you print return and print the array before the promises resolve).

However you can alwayd use a regular for loop to filter iterables. Like this:

let testArray = [
{
id: 'stringId1',
data: {
someDoc: {
moreContent: 'Some random content',
type: 'noInterest'
}
}
},
{
id: 'stringId2',
data: {
someDoc: {
moreContent: 'Some random content',
type: 'ofInterest'
}
}
},
{
id: 'stringId3',
data: {
someDoc: {
moreContent: 'Some random content',
type: 'ofInterest'
}
}
}
]

async function booleanWhenGood(id) {
if (id in { 'stringId1': 1, 'stringId2': 1 }) { // mock object
return { myBoolean: true };
} else {
return { myBoolean: false };
}
}

async function main() {
let filtered = []
for (item of testArray)
if ((await booleanWhenGood(item.id)).myBoolean && item.data.someDoc.type === 'ofInterest')
filtered.push(item)
console.log('filtered :>> ', filtered);
}

main()

Kubectl get only nodes with status ready

You can do this

kubectl get nodes | grep Ready

or you can do this

JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]} 
{@.type}={@.status};{end}{end}' \
&& kubectl get nodes -o jsonpath="$JSONPATH" | grep "Ready=True"

How to run a pipeline except for a few nodes?

To filter out a few lines of a pipeline you can simply filter the pipeline list from inside of python, my favorite way is to use a list comprehension.

by name

nodes_to_run = [node for node in pipeline.nodes if 'dont_run_me' not in node.name]
run(nodes_to_run, io)

by tag

nodes_to_run = [node for node in pipeline.nodes if 'dont_run_tag' not in node.tags]
run(nodes_to_run, io)

It's possible to filter by any attribute tied to the pipeline node, (name, inputs, outputs, short_name, tags)

If you need to run your pipeline this way in production or from the command line, you can either tag your pipeline to run with tags, or add a custom click.option to your run function inside of kedro_cli.py then run this filter when the flag is True.

Note
This assumes that you have your pipeline loaded into memory as pipeline and catalog loaded in as io



Related Topics



Leave a reply



Submit