V
V
Vladislav Kadun2018-08-26 20:38:30
PHP
Vladislav Kadun, 2018-08-26 20:38:30

How to create such a filter for MongoDB, PHP?

You need to make the following query in MongoDB using PHP:
There is a database. The database has a collection. The collection contains documents. The documents have an array. You need to select this document if there is a certain value in the array. NOT ONLY THIS value, but others are allowed.
I did this: But in this scenario, MongoDB selects a document if it contains ONLY the value I specified. That is, with an array of type [$id, $id2, $id3] the document will not be selected
$filter = array('admins' => array($id));

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
forspamonly2, 2018-08-26
@forspamonly2

probably, you have an extra second array.
if the monge does not specify an array for a filter by a field with an array, but simply a value, it searches for it by occurrence.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question