Jump to content
php.lv forumi

Recommended Posts

Posted

Labdien,

 

Vēlējos apjautāties kā pareizi jāveido MongoDB aggregate pieprasījums ar PHP palīdzību ?

 

Meiģināšu šādu: http://php.net/manual/en/mongocollection.aggregate.php, bet neizdodas.

 

Stāv Xampp ar PHP 5.6 uz Windows 7.

 

Dataseti:

{
    "_id": {
        "$oid": "58868a5737d44aec0c86ea7d"
    },
    "serial": "0002100032",
    "topic": "TEMPERATURE",
    "payload": {
        "temp-ch1-0002100032": "46.50"
    },
    "_msgid": "dbf9bde5.643f6",
    "timestamp": "2017-01-23T22:57:27.741Z"
}

{
    "_id": {
        "$oid": "58868a5737d44aec0c86ea7f"
    },
    "serial": "0002100032",
    "topic": "TEMPERATURE",
    "payload": {
        "temp-ch2-0002100032": "40.19"
    },
    "_msgid": "dbf9bde5.643f6",
    "timestamp": "2017-01-23T22:57:27.748Z"
}

{
    "_id": {
        "$oid": "58868b8137d44aec0c86eaa7"
    },
    "serial": "0002100032",
    "topic": "TEMPERATURE",
    "payload": {
        "temp-ch1-0002100032": "46.50"
    },
    "_msgid": "76b17f37.89414",
    "timestamp": "2017-01-23T23:02:25.745Z"
}

{
    "_id": {
        "$oid": "58868b8137d44aec0c86eaa9"
    },
    "serial": "0002100032",
    "topic": "TEMPERATURE",
    "payload": {
        "temp-ch2-0002100032": "40.19"
    },
    "_msgid": "76b17f37.89414",
    "timestamp": "2017-01-23T23:02:25.750Z"
}

Vēlos nosummēt "temp-ch2-0002100032".

$usage = $db->Usage->aggregate(array('$serial' => array('payload' => 'temp-ch1-6F0011')));

Loģiski kļūda:

Fatal error: Uncaught exception 'MongoResultException' with message 'ds029486.mlab.com:29486: Unrecognized pipeline stage name: '$serial'' in C:\xampp2\htdocs\mongodb.php:8 Stack trace: #0 C:\xampp2\htdocs\mongodb.php(8): MongoCollection->aggregate(Array) #1 {main} thrown in C:\xampp2\htdocs\mongodb.php on line 8

Aizmirsu piemirst, ka MongoDB esmu izcils iesācējs, bet pats MongoDB strādā un saslēgums strādā, `find` var pielietot un izgūt kādu rezultātu.

 

Ceru uz izpratni.

 

Posted (edited)

Pārliecinies, ka datubāzes versija atbilst manuālim, pēc kura vadies. Bezmaksas hostings nesteidzās un mongodb versiju neatjauno.

Edited by Wuu
Posted

Kāds hostings, viņam xampp uz sava PC stāv.

 

O rly, "ds029486.mlab.com:29486"?

 

NBS, esi pārliecināts, ka tas ko tu vēlies izdarīt tiek atbalstīts mongd 3.2 versijā?

Posted

No mlab.com cik var noprast: mongod version: 3.2.11 (MMAPv1)

Protams, vai viņi nemelo to jau es nezinu.

Pieprasījumus veicu lokāli vai tas ko ietekmē nav ne jausmas.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...