R
R
raxanucu2017-03-12 10:23:34
PHP
raxanucu, 2017-03-12 10:23:34

MongoDB how to correctly compose a query consisting of many parameters?

Actually, it is necessary to organize a search, but it is not entirely clear how to do this if there are 13 parameters, besides, any of them may not be. Obviously, we cannot consider all options. No, in general we can, but it’s scary to imagine how long it will take, and it’s not at all clear how to support it. So, what is the algorithm to solve the problem? How to make such requests? I write in PHP.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Gusev, 2017-03-16
@illi

Take all the parameters that came in, for example 5 out of 13, and form the request object:
JSON

{
param1:val1,
param2: {$exists: true}
$or: [{param3:val3}, {param4:val4}]
}

And feed this object to the monge.
If there is no parameter, you simply do not add it to the collected request object.

O
Oleg Bukatchuk, 2017-03-16
@olegbukatchuk

Imagine that you are working with arrays of different nesting depths. This makes it easier to understand which approach to use.
Here, the process is available:
www.codeisart.ru/blog/creating-parsing-json-data-php
Documentation:
php.net/manual/ru/function.json-encode.php
php.net/manual/ru/ function.json-decode.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question