Можно ли сделать два или более $in
в одном запросе?
Мой код: find({_id: { $in: [ObjectId("5e96c5b11000ae32d0742d94")] } })
Здесь я хочу сделать еще один $in
для фильтрации моего MongoDB.
(я могу показать вам структуру моей базы, если кто-нибудь захочет)
Надеюсь, это понятно.
Вот результат find()
(здесь только 6 адрес у меня есть намного больше, но нам все равно):
object(MongoDB\Model\BSONDocument)#5604 (1) { ["storage":"ArrayObject":private]=> array(2) { ["_id"]=> object(MongoDB\BSON\ObjectId)#5630 (1) { ["oid"]=> string(24) "5e96c5b11000ae32d0742d94" } [0]=> string(5104518) "
{"id":"05009","type":"municipality","name":"Aspres-lès-Corps","postcode":["05800"],"citycode":"05009","lon":6.0005,"lat":44.8118,"x":937174.73,"y":6417022.74,"population":107,"city":"Aspres-lès-Corps","context":"05, Hautes-Alpes, Provence-Alpes-Côte d'Azur","importance":0.18009340385621533}
{"id":"05024","type":"municipality","name":"Valdoule","postcode":["05150"],"citycode":"05024","lon":5.5233,"lat":44.4615,"x":900711.69,"y":6376812.41,"population":212,"city":"Valdoule","context":"05, Hautes-Alpes, Provence-Alpes-Côte d'Azur","importance":0.21360128697297767}
{"id":"05031","type":"municipality","name":"Champcella","postcode":["05310"],"citycode":"05031","lon":6.5242,"lat":44.7193,"x":979003.59,"y":6408468.91,"population":185,"city":"Champcella","context":"05, Hautes-Alpes, Provence-Alpes-Côte d'Azur","importance":0.20689148370809196}
{"id":"05032","type":"municipality","name":"Champoléon","postcode":["05260"],"citycode":"05032","lon":6.2619,"lat":44.7429,"x":958141.88,"y":6410195.7,"population":144,"city":"Champoléon","context":"05, Hautes-Alpes, Provence-Alpes-Côte d'Azur","importance":0.19459101490553132}
{"id":"05033","type":"municipality","name":"Chanousse","postcode":["05700"],"citycode":"05033","lon":5.6606,"lat":44.3633,"x":911996.46,"y":6366268.17,"population":40,"city":"Chanousse","context":"05, Hautes-Alpes, Provence-Alpes-Côte d'Azur","importance":0.13312939135127264}
{"id":"05035","type":"municipality","name":"Châteauneuf-d'Oze","postcode":["05400"],"citycode":"05035","lon":5.8979,"lat":44.5038,"x":930323.7,"y":6382530.99,"population":28,"city":"Châteauneuf-d'Oze","context":"05, Hautes-Alpes, Provence-Alpes-Côte d'Azur","importance":0.11676874579085184}
И вот где я беру файл: https://adresse.data.gouv.fr/data/ban/adresses/latest/addok/adresses-addok-05.ndjson.gz
I импортировать данные через контроллер в php:
$connection = new MongoClient();
$db = $connection->france;
$collection = $db->adress05;
$collection->insert($jsonarray);
И я конвертирую это так:
$ndjsongz=file_get_contents('https://adresse.data.gouv.fr/data/ban/adresses/latest/addok/adresses-addok-05.ndjson.gz');
$ndjson=gzdecode($ndjsongz);
$bsonarray=explode("}",$ndjson, true);
$json = MongoDB\BSON\toJSON(MongoDB\BSON\fromPHP($bsonarray));
$jsonarray = json_decode($json);
Спасибо