Q
Q
Qubert2014-07-24 14:58:57
PHP
Qubert, 2014-07-24 14:58:57

How to save json to mongoDB using PHP?

Hello!
i get json string and i want to store it in mongo using php like this:

$mongo = new MongoClient(); 
$db = $mongo->database;

// access collection
$collection = $db->collection;
$collection->insert($_POST['data']);

what could be the problem, thank you very much for your help!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Entelis, 2014-07-24
@DmitriyEntelis

$m = new MongoClient();
$collection = $m->selectCollection('test', 'phpmanual');

// If an array literal is used, there is no way to access the generated _id
$collection->insert(array('x' => 1));

php.net/manual/ru/mongocollection.insert.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question