如何使用Laravel在MongoDB中创建Blob [英] How to create a blob in MongoDB using laravel

查看:184
本文介绍了如何使用Laravel在MongoDB中创建Blob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Laravel4 PHP Framework,我的Web应用程序必须处理JSON格式的API.

I am using Laravel4 PHP Framework, my web application has to handle JSON format APIs.

我的问题的第一部分是,每次我获得订阅时,Web应用程序都会收到deviceID和listID(其中list ID是具有deviceID的设备所订阅的列表). 对于收到的每个deviceID,我们必须创建一个具有deviceID之类的blob,例如

First part of My problem is, each time when i get a subscription, deviceID and listID (where list ID is the the list which was subscribed by the device having deviceID) is received by the web application. For each deviceID received we have to create a blob having deviceID like

{
    deviceID:........,
    subscription:[{listID:1},{listID:2}.......]
}

当同一台设备订阅多个列表时,我必须更新订阅,类似地,当新设备订阅时,必须如上所述创建一个新文档.

when the same device subscribe multiple list i have to update subscription, similerly when new device subscribes, a new document has to be created as above.

我的问题的第二部分是我们的网络将为每个列表创建一个报价活动,每个活动将具有标题,图标,图像,详细说明等内容. 当广告系列处于启用状态时,该广告系列必须插入以提供上述文档数组作为对象,例如:

Second part of my problem is our web will create a offer campaigns for each Lists.Each campaign would have fiels like Title, Icon, Image,Detailed description etc. when a campaign is ON, this campaign has to inserted in to offers array of above document as an object Like:

{
    deviceID:........,
    subscription:[{listID:1},{listID:2}.......],
    offers [{campaign1}]
}

该广告系列将包含许多字段.

The campaign would have many fields.

我尝试过

db.subscribers.insert(
{
    _id:98745334,
    subscriptions: [{
        list_id: "14Q3"}, {list_id: "8989"}
    ],
    offers: [ { title: "50% off", qty: 25 }, { title: "20% off", qty: 50 } ],
})

这行得通. 但, 我无法使用Laravel4插入或检索或更新任何数据.

This worked. But, I couldn't insert or retrieve or updaate any data using Laravel4.

我正在使用MongoDB和Laravel4

I am using MongoDB and Laravel4

对不起,英语不好 请帮助我

Sorry for bad english Please help me

推荐答案

我成功插入了以下内容

       DB::connection('mongodb')->collection('subscribers')->insert(array(
           '_id' => $subscriber->device_id,
           'subscriptions' => array(array('list_id' => $subscriber->list1_id)),
          ));

为了推送到Subscriptions数组,我使用了以下代码

For pushing into Subscriptions array I used following code

Subscription::where('_id',$subscriber->device_id)->push('subscriptions', array('list_id' => $subscriber->list1_id)); 

这篇关于如何使用Laravel在MongoDB中创建Blob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆