How to exclude elements in queries?


#1

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


#2

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


#3

Thank you.

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


#4

Documentation on the MongoDB query syntax is available here.