Kan niet alle Mongo-documenten ophalen met een query - slechts enkele worden geretourneerd

Ik ondervind problemen bij het ophalen van alle documenten die overeenkomen met een zoekopdracht op MongoDB. Ik gebruik PHP.

Hier is een snelle test:

## Document 1   

{
   "_id": ObjectId("4ea80a1eb73e26ef1500cc9e"),
   "search": {
   "0": "clothing",
   "1": "golden",
    ....etc

## Document 2
{
   "_id": ObjectId("4ea81e78b73e26ef15339c65"),
   "search": {
     "0": "and",
     "1": "belt",
     "2": "brown",
     "3": "golden",
    ...etc

## query
$search = array('golden');
$products = Products::all( array('search'=>array('$in'=> $search )))//only document 1 is returned.
//this is a quick test. in the end I'd like to have:
$search = array('golden', 'belt'); //document 2 is returned

Documenten worden gemaakt op basis van een PHP-array, waarbij 'zoeken' een gesorteerde en unieke reeks tekenreekselementen is:     sort ($ search);     $ search = array_unique ($ search);

$new->setProperty('search', $search);

Ik ben vrij nieuw voor Mongo, maar ik begrijp niet waarom, als de syntaxis van mijn document niet correct is, er één wordt teruggestuurd in plaats van niets.

Dank je.

0

1 antwoord

Ik weet niet wat in PHP, maar dit werkt:

> db.items.find({})
{ "_id" : ObjectId("4ea98d0fa287fedc0281feee"), "name" : "first", "keywords" : [ "one", "two", "three", "four" ] }
{ "_id" : ObjectId("4ea98d1aa287fedc0281feef"), "name" : "first", "keywords" : [ "two", "three", "four", "five" ] }
{ "_id" : ObjectId("4ea98d23a287fedc0281fef0"), "name" : "first", "keywords" : [ "four", "five", "six" ] }
{ "_id" : ObjectId("4ea99243a287fedc0281fef1"), "name" : "first", "keywords" : [ "five", "six" ] }
{ "_id" : ObjectId("4ea99247a287fedc0281fef2"), "name" : "first", "keywords" : [ "five", "six", "seven" ] }
{ "_id" : ObjectId("4ea99273a287fedc0281fef3"), "name" : "first", "keywords" : [ "one", "two", "seven" ] }
{ "_id" : ObjectId("4ea9927aa287fedc0281fef4"), "name" : "first", "keywords" : [ "one", "two", "seven" ] }
> db.items.find({$or:[{keywords:"four"},{keywords:"five"}]})
{ "_id" : ObjectId("4ea98d0fa287fedc0281feee"), "name" : "first", "keywords" : [ "one", "two", "three", "four" ] }
{ "_id" : ObjectId("4ea98d1aa287fedc0281feef"), "name" : "first", "keywords" : [ "two", "three", "four", "five" ] }
{ "_id" : ObjectId("4ea98d23a287fedc0281fef0"), "name" : "first", "keywords" : [ "four", "five", "six" ] }
{ "_id" : ObjectId("4ea99243a287fedc0281fef1"), "name" : "first", "keywords" : [ "five", "six" ] }
{ "_id" : ObjectId("4ea99247a287fedc0281fef2"), "name" : "first", "keywords" : [ "five", "six", "seven" ] }
> db.items.find({keywords:{$in:["four","five"]}})
{ "_id" : ObjectId("4ea98d0fa287fedc0281feee"), "name" : "first", "keywords" : [ "one", "two", "three", "four" ] }
{ "_id" : ObjectId("4ea98d1aa287fedc0281feef"), "name" : "first", "keywords" : [ "two", "three", "four", "five" ] }
{ "_id" : ObjectId("4ea98d23a287fedc0281fef0"), "name" : "first", "keywords" : [ "four", "five", "six" ] }
{ "_id" : ObjectId("4ea99243a287fedc0281fef1"), "name" : "first", "keywords" : [ "five", "six" ] }
{ "_id" : ObjectId("4ea99247a287fedc0281fef2"), "name" : "first", "keywords" : [ "five", "six", "seven" ] }
0
toegevoegd
Zo geprobeerd, nog steeds geen geluk: $ products = Producten :: all (array ('$ or' => array (array ('search' => "golden")))); - slechts enkele documenten worden geretourneerd, maar niet document 2.
toegevoegd de auteur koichirose, de bron
Dit is hetzelfde als ik mijn vraag in de shell uitvoer of via een webbeheerder zoals RockMongo
toegevoegd de auteur koichirose, de bron