mardi 12 janvier 2016

db.runcommand working on mongoshell giving result but not working with php

This is the query with php for search according to latLong also created 2d sphere index feild .but not working.

$db = DB::getMongoDB();
$r = $db->command(array( 'geoNear' => "sale_event",'near' => array( 'type' => "Point", 'coordinates' => array('76.7171945','30.7291196')), 'spherical' => true, ));

This command is working fine on mongo shell and giving results .

db.runCommand(    {      geoNear: "sale_event",      near: { type: "Point", coordinates: [ 76.7171945,30.7291196 ] },      spherical: true,        } )

Here I am pasting result of mongo shell after running the above command in shell:

{
"results" : [
    {
        "dis" : 0,
        "obj" : {
            "_id" : ObjectId("568e01fc04896fcd208b4575"),
            "seller_rating" : "4.5",
            "status" : "1",
            "title" : "we're",
            "quantity_ordered" : "100",
            "sale_event_longitude" : 76.7171945,
            "image" : "test image",
            "repeat_every_friday" : false,
            "price_in_primary_currency" : "1325",
            "repeat_every_sunday" : false,
            "quantity_available" : "13455",
            "pick_up_or_delivery" : "Pickup",
            "primary_currency" : "SGD",
            "quantity_delivered" : "10",
            "delivery_radius_in_km" : "No delivery",
            "repeat_every_thursday" : false,
            "sale_event_latitude" : 30.7291196,
            "repeat_every_saturday" : false,
            "type" : "Chinese",
            "restriction" : "Vegetarian",
            "repeat_every_monday" : false,
            "seller_address_id" : "568e01a804896fcd208b4570",
            "seller_user_id" : "568e008204896fcd208b456f",
            "repeat_every_wednesday" : false,
            "item_id" : "568e01d904896fcd208b4572",
            "repeat_every_tuesday" : false,
            "image_thumbnail" : "test image 2",
            "latLong" : [
                76.7171945,
                30.7291196
            ],
            "description" : "Where'd",
            "updated_at" : ISODate("2016-01-07T06:13:16.152Z"),
            "created_at" : ISODate("2016-01-07T06:13:16.150Z"),
            "pickup_date_delivery_and_time_from" : ISODate("2016-01-07T11:40:34Z"),
            "pickup_delivery_date_and_time_to" : ISODate("2016-01-09T11:40:36Z")
        }
    },
    {
        "dis" : 244708.75191385587,
        "obj" : {
            "_id" : ObjectId("568e01eb04896fcd208b4574"),
            "seller_rating" : "4.5",
            "status" : "1",
            "title" : "we're",
            "quantity_ordered" : "100",
            "sale_event_longitude" : 77.0999578,
            "image" : "test image",
            "repeat_every_friday" : false,
            "price_in_primary_currency" : "1325",
            "repeat_every_sunday" : false,
            "quantity_available" : "2345",
            "pick_up_or_delivery" : "Pickup",
            "primary_currency" : "SGD",
            "quantity_delivered" : "10",
            "delivery_radius_in_km" : "No delivery",
            "repeat_every_thursday" : false,
            "sale_event_latitude" : 28.5561624,
            "repeat_every_saturday" : false,
            "type" : "Chinese",
            "restriction" : "Vegetarian",
            "repeat_every_monday" : false,
            "seller_address_id" : "568e01b804896fcd208b4571",
            "seller_user_id" : "568e008204896fcd208b456f",
            "repeat_every_wednesday" : false,
            "item_id" : "568e01d904896fcd208b4572",
            "repeat_every_tuesday" : false,
            "image_thumbnail" : "test image 2",
            "latLong" : [
                77.0999578,
                28.5561624
            ],
            "description" : "Where'd",
            "updated_at" : ISODate("2016-01-07T06:12:59.263Z"),
            "created_at" : ISODate("2016-01-07T06:12:59.261Z"),
            "pickup_date_delivery_and_time_from" : ISODate("2016-01-07T11:40:15Z"),
            "pickup_delivery_date_and_time_to" : ISODate("2016-01-08T11:40:17Z")
        }
    }
],
"stats" : {
    "nscanned" : 20,
    "objectsLoaded" : 2,
    "avgDistance" : 122354.37595692794,
    "maxDistance" : 244708.75191385587,
    "time" : 3
},
"ok" : 1

}

Now am executing code in php laravel :

$db = DB::getMongoDB();
$r = $db->command(array( 'geoNear' => "sale_event",'near' => array( 'type' => "Point", 'coordinates' => array('76.7171945','30.7291196')), 'spherical' => true, ));

Response am getting :

Array
(
 [ok] => 0
 [errmsg] => can't find ns
)

I am using mongodb.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire