sql >> Database teknologi >  >> NoSQL >> MongoDB

MongoDB Collection runCommand fra PHP

Dette er et mere omfattende eksempel på Mongo Text Search-brug i PHP

<?php

$m = new MongoClient(); // connect
$db = $collection = $m->foo; // get the database named "foo"
$collection = $db->bar; // get the collection "bar" from database named "foo"

$collection->ensureIndex(
    array(
        'title' => 'text',
        'desc' => 'text',
    ),
    array(
        'name' => 'ExampleTextIndex',
        'weights' => array(
            'title' => 100,
            'desc' => 30,
        ),
        'timeout' => 60000000
    )
);

$result = $db->command(
    array(
        'text' => 'bar', //this is the name of the collection where we are searching
        'search' => 'hotel', //the string to search
        'limit' => 5, //the number of results, by default is 1000
        'project' => Array( //the fields to retrieve from db
            'title' => 1
        )
    )
); 

print_r($result);


  1. Hvordan samles på et stort array i mongoDB?

  2. Hvordan laver man en forespørgselsdato i mongodb ved hjælp af pymongo?

  3. MongoDB/PyMongo:Forespørgsel på flere kriterier - uventede resultater

  4. Hvordan får man de sidste N poster i mongodb?