duanqiang5722 2015-07-29 14:31
浏览 133

MongoDB,如何将对象插入到新集合中?

I have a return object coming from instagram. I am trying to skate the entire build DB table structure process, I understand Mongo is the ideal DB to use for this task.

I am using the regular instagram libraries https://github.com/cosenary/Instagram-PHP-API and my test code runs without error. I don have the PhP PECL mongo libraries installed, I should be good to go.

session_start();
require 'vendor/autoload.php';
use MetzWeb\Instagram\Instagram;
$instagram = new Instagram(array(
  'apiKey'      => 'xxx',
  'apiSecret'   => 'xxx',
  'apiCallback' => 'http://103.238.173.97/success.php'
  ));

$accessToken = $instagram->getAccessToken();
$_SESSION['InstagramAccessToken'] = $accessToken;
$instagram->setAccessToken($_SESSION['InstagramAccessToken']);
$popular = $instagram->getPopularMedia();
// After getting the response, let's iterate the payload
var_dump($popular);

added just now:

$conn = new MongoClient('mongodb://localhost/?w=1');

$db = $conn->instagram;

// access collection
$collection = $db->instagram1;
$collection->insert($popular);

How would I construct a PDO query to 'autobuild' the table structure just like the JSON object at reply from my request?

instagram JSON object

Repaste of object. Most got cut off due to size

Update: I tried to insert straight into a collection, I get no error but the DB is still the same size

show dbs Data 0.078GB admin (empty) instagram 0.078GB local 0.078GB test 0.078GB week1 (empty)

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮