MONGODB和LARAVEL 5.1。我今天需要更新所有的文档,我该怎么做?

MONGODB和LARAVEL 5.1。我今天需要更新所有的文档,我该怎么做?,mongodb,laravel-5.1,Mongodb,Laravel 5.1,我需要在今天或昨天的同一天更新所有文件, 我该怎么做 这是我当前的代码: $yesterday = new DateTime('-1 days'); $yesterday = $fecha->format('Y-m-d'); $yesterday = new MongoDate(strtotime($yesterday.'00:00:00')); $date=CampaignLog::where('campaign_id',$id)->where('updated_at','=',

我需要在今天或昨天的同一天更新所有文件, 我该怎么做

这是我当前的代码:

$yesterday = new DateTime('-1 days');
$yesterday = $fecha->format('Y-m-d');
$yesterday = new MongoDate(strtotime($yesterday.'00:00:00'));

$date=CampaignLog::where('campaign_id',$id)->where('updated_at','=', $yesterday)->get(array('data'));

Laravel的Eloquent支持Carbon/DateTime对象,而不是MongoDate对象,MongoDate对象在保存到数据库时将在内部转换为MongoDate对象。您可以使用laravel中名为的数据处理包进行查询

例如,如果要从
活动日志
数据中查询mongodb datetime字段在更新的时间大于给定日期的记录,例如昨天的记录,请使用Carbon的辅助方法:

$dt = Carbon::yesterday();
$campaigns = CampaignLog::where('updated_at', '>=', $dt)->get();
类似地,要进行数据范围查询,即查询“现在”和“昨天”之间的记录,请使用
whereBetween
方法:

$campaigns = CampaignLog::whereBetween(
             'updated_at', array(
                 Carbon::yesterday(),
                 Carbon::now()
             )
         )->get();
另一种方法是使用,它允许您使用Carbon/DateTime对象而不是MongoDate对象。示例来源于

<?php

use Jenssegers\Mongodb\Model as Eloquent;

class CampaignLog extends Eloquent {

    use SoftDeletingTrait;

    /**
     * Collection for Model
     *
     * @var String
     */
    protected $collection = "campaignlogs";

    /**
     * Connection for model
     *
     * @var type
     */
    protected $connection = 'mongodb';

    protected $dates = array('updated_at');
}
或者本机使用MongoDate对象,您可以尝试

$start = new MongoDate(strtotime("yesterday"));
$stop = new MongoDate();

$campaigns = DB::collection('campaignlog')->whereBetween('updated_at', array($start, $stop))->get();

谢谢你的回答。但是在今天和昨天的日子里,我的更新并不是在中间的例子,今天是26,只想带来第二十六个,把这个开始=新的日期(SttoTimes(“1天”));MongoDate停止=新建();$CAM活动日志:=在哪里(‘Actudio ID’,$ID)>何处(‘UpDeDeDAT',‘>’,新的DATETIME(‘1天’))-在何处(‘UpDATEDATA’,’尝试下面的代码,但是在今天和昨天的日子里带来我更新的不是今天中间的例子是26,并且只带第二十六个并把这个$St= =新的MangGODE(SRTOTIME(”-1天))$MongoDate stop=new();$cam活动日志::=where('campaign_id',$id)->where('updated_at','>',new DateTime('-1天'))->where('updated_at','
$start = new MongoDate(strtotime("yesterday"));
$stop = new MongoDate();

$campaigns = DB::collection('campaignlog')->whereBetween('updated_at', array($start, $stop))->get();