How to exclude elements in queries?

To MP team:

I would like to collect only sp and spd systems from the database.

I have been doing it this way, and it seems like it doesn’t work:

datas = m.query(criteria = {“band_gap”: 0.0,
“nelements”: 2,
“elements”: {"$in": [“H”,“Li”, “Be”, “Mg”, “B”, “C”, “N”, “O”, “F”, “Na”, “Mg”, “Al”, “Si”, “Cl”, “K”, “Ca”]}},
properties=[“pretty_formula”, “material_id”, “formula”, “spacegroup.symbol”,“band_gap”])

I’m thinking instead of including elements is there a way that I can exclude element?

Also, do you know any documentation of the syntax of “elements” in the queries?

Sincerely,

Howard Yanxon

Hi @yanxonh, you can use the operator "$nin" to exclude elements (the query uses MongoDB syntax).

1 Like

Thank you.

Do you know a link to this syntax ($in, $all, $nin)?

Documentation on the MongoDB query syntax is available here.