D
D
danys_kun2020-09-13 17:08:29
Python
danys_kun, 2020-09-13 17:08:29

MongoDB how to do a search on two values?

I need to do a search on two values ​​in documents.

The code itself:

...
      if collection.count_documents({"id": member.id}) * collection.count_documents({"server_id": guild.id}) == 0:
        collection.insertMany({
                                ...
        })
      else:
 				pass


Tried a lot of things. And find and just count_documents. If you use find, then nothing is added to the database at all. If you use the code above, then an error occurs. If it's simple:
if collection.count_documents({"id": member.id, "server_id": guild.id}) == 0:
then only 3 are added, instead of 9. Because a duplicate error occurs.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question