3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php /*{ "_id" : ObjectId("595baefce2810a6a8a94fe2d"), "user" : "1234abc", "type" : "session-started", "name" : "moja o sesja", "reference_id" : "hippo-123", "created_on" : ISODate("2017-01-01T01:01:01.123Z") }*/ class A { private static $_id = 0x10a6a8a94fe2d; private $user; private $type; private $reference_id; private $created_on; public function __construct($user, $type, $reference_id, $created_on) { $this->user = $user; $this->type = $type; $this->reference_id = $reference_id; $this->created_on = $created_on; } public function __toString() { return sprintf('{ "_id": ObjectId("595baefce28%x"), "user": "%s", "type": "%s", "name": "my %s", "reference_id": "%s%s", "created_on": ISODate("%s.000Z") }', ++self::$_id, $this->user, $this->type, $this->type, $this->user, $this->reference_id ? 'hippo-' . $this->reference_id : '', $this->created_on ); } } $history = [ new A('u1', 'onboarded', '', '2017-01-01T01:01:01'), new A('u1', 'category_activated', 11, '2017-01-01T01:02:01'), new A('u1', 'category_started', 11, '2017-01-01T01:03:01'), new A('u1', 'series_started', 21, '2017-01-01T01:04:01'), new A('u1', 'session_started', 31, '2017-01-01T01:05:01'), new A('u1', 'session_progress_updated', 31, '2017-01-01T01:06:01'), new A('u1', 'session_completed', 31, '2017-01-01T01:07:01'), new A('u1', 'session_started', 32, '2017-01-01T01:08:01'), new A('u1', 'session_completed', 32, '2017-01-01T01:09:01'), // seesion completed (2/2) new A('u1', 'session_started', 33, '2017-01-02T01:10:01'), new A('u1', 'session_completed', 33, '2017-01-02T01:11:01'), // session completed (1/1) new A('u1', 'session_started', 34, '2017-01-03T01:12:01'), // session started (0/1) new A('u1', 'session_completed', 34, '2017-01-04T01:13:01'), // session completed (1/1) new A('u2', 'onboarded', '', '2017-01-01T01:01:01'), new A('u2', 'category_activated', 11, '2017-01-01T01:02:01'), new A('u2', 'category_started', 11, '2017-01-01T01:03:01'), new A('u2', 'series_started', 21, '2017-01-01T01:04:01'), new A('u2', 'session_started', 31, '2017-01-01T01:05:01'), new A('u2', 'session_progress_updated', 31, '2017-01-01T01:06:01'), new A('u2', 'session_completed', 31, '2017-01-01T01:07:01'), new A('u1', 'session_started', 35, '2017-01-05T01:14:01'), new A('u1', 'session_progress_updated', 35, '2017-01-05T01:15:01'), new A('u1', 'session_completed', 35, '2017-01-05T01:16:01'), new A('u1', 'session_started', 36, '2017-01-05T01:17:01'), // session started (1/2) new A('u1', 'session_skipped', 36, '2017-01-06T01:18:01'), // session skipped (0/1) new A('u1', 'session_started', 37, '2017-01-07T01:19:01'), new A('u1', 'session_completed', 37, '2017-01-07T01:20:01'), // session completed (1/1) //new A('u1', 'session_started', 34, '2017-01-09T01:21:01'), // day skipped new A('u1', 'session_started', 38, '2017-01-09T01:21:01'), new A('u1', 'session_completed', 38, '2017-01-09T01:21:01'), ]; echo 'db.activities.insertMany([' . implode(',', $history) . ']);';
based on 8AB25
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.2.6
db.activities.insertMany([{ "_id": ObjectId("595baefce2810a6a8a94fe2e"), "user": "u1", "type": "onboarded", "name": "my onboarded", "reference_id": "u1", "created_on": ISODate("2017-01-01T01:01:01.000Z") },{ "_id": ObjectId("595baefce2810a6a8a94fe2f"), "user": "u1", "type": "category_activated", "name": "my category_activated", "reference_id": "u1hippo-11", "created_on": ISODate("2017-01-01T01:02:01.000Z") },{ "_id": ObjectId("595baefce2810a6a8a94fe30"), "user": "u1", "type": "category_started", "name": "my category_started", "reference_id": "u1hippo-11", "created_on": ISODate("2017-01-01T01:03:01.000Z") },{ "_id": ObjectId("595baefce2810a6a8a94fe31"), "user": "u1", "type": "series_started", "name": "my series_started", "reference_id": "u1hippo-21", "created_on": ISODate("2017-01-01T01:04:01.000Z") },{ "_id": ObjectId("595baefce2810a6a8a94fe32"), "user": "u1", "type": "session_started", "name": "my session_started", "reference_id": "u1hippo-31", "created_on": ISODate("2017-01-01T01:05:01.000Z") },{ "_id": ObjectId("595baefce2810a6a8a94fe33"), "user": "u1", "type": "session_progress_updated", "name": "my session_progress_updated", "reference_id": "u1hippo-31", "created_on": ISODate("2017-01-01T01:06:01.000Z") },{ "_id": ObjectId("595baefce2810a6a8a94fe34"), "user": "u1", "type": "session_completed", "name": "my session_completed", "reference_id": "u1hippo-31", "created_on": ISODate("2017-01-01T01:07:01.000Z") },{ "_id": ObjectId("595baefce2810a6a8a94fe35"), "user": "u1", "type": "session_started", "name": "my session_started", "reference_id": "u1hippo-32", "created_on": ISODate("2017-01-01T01:08:01.000Z") },{ "_id": ObjectId("595baefce2810a6a8a94fe36"), "user": "u1", "type": "session_completed", "name": "my session_completed", "reference_id": "u1hippo-32", "created_on": ISODate("2017-01-01T01:09:01.000Z") },{ "_id": ObjectId("595baefce2810a6a8a94fe37"), "user": "u1", "type": "session_started", "name": "my session_started", "reference_id": "u1hippo-33", "created_on": ISODate("2017-01-02T01:10:01.000Z") },{ "_id": ObjectId("595baefce2810a6a8a94fe38"), "user": "u1", "type": "session_completed", "name": "my session_completed", "reference_id": "u1hippo-33", "created_on": ISODate("2017-01-02T01:11:01.000Z") },{ "_id": ObjectId("595baefce2810a6a8a94fe39"), "user": "u1", "type": "session_started", "name": "my session_started", "reference_id": "u1hippo-34", "created_on": ISODate("2017-01-03T01:12:01.000Z") },{ "_id": ObjectId("595baefce2810a6a8a94fe3a"), "user": "u1", "type": "session_completed", "name": "my session_completed", "reference_id": "u1hippo-34", "created_on": ISODate("2017-01-04T01:13:01.000Z") },{ "_id": ObjectId("595baefce2810a6a8a94fe3b"), "user": "u2", "type": "onboarded", "name": "my onboarded", "reference_id": "u2", "created_on": ISODate("2017-01-01T01:01:01.000Z") },{ "_id": ObjectId("595baefce2810a6a8a94fe3c"), "user": "u2", "type": "category_activated", "name": "my category_activated", "reference_id": "u2hippo-11", "created_on": ISODate("2017-01-01T01:02:01.000Z") },{ "_id": ObjectId("595baefce2810a6a8a94fe3d"), "user": "u2", "type": "category_started", "name": "my category_started", "reference_id": "u2hippo-11", "created_on": ISODate("2017-01-01T01:03:01.000Z") },{ "_id": ObjectId("595baefce2810a6a8a94fe3e"), "user": "u2", "type": "series_started", "name": "my series_started", "reference_id": "u2hippo-21", "created_on": ISODate("2017-01-01T01:04:01.000Z") },{ "_id": ObjectId("595baefce2810a6a8a94fe3f"), "user": "u2", "type": "session_started", "name": "my session_started", "reference_id": "u2hippo-31", "created_on": ISODate("2017-01-01T01:05:01.000Z") },{ "_id": ObjectId("595baefce2810a6a8a94fe40"), "user": "u2", "type": "session_progress_updated", "name": "my session_progress_updated", "reference_id": "u2hippo-31", "created_on": ISODate("2017-01-01T01:06:01.000Z") },{ "_id": ObjectId("595baefce2810a6a8a94fe41"), "user": "u2", "type": "session_completed", "name": "my session_completed", "reference_id": "u2hippo-31", "created_on": ISODate("2017-01-01T01:07:01.000Z") },{ "_id": ObjectId("595baefce2810a6a8a94fe42"), "user": "u1", "type": "session_started", "name": "my session_started", "reference_id": "u1hippo-35", "created_on": ISODate("2017-01-05T01:14:01.000Z") },{ "_id": ObjectId("595baefce2810a6a8a94fe43"), "user": "u1", "type": "session_progress_updated", "name": "my session_progress_updated", "reference_id": "u1hippo-35", "created_on": ISODate("2017-01-05T01:15:01.000Z") },{ "_id": ObjectId("595baefce2810a6a8a94fe44"), "user": "u1", "type": "session_completed", "name": "my session_completed", "reference_id": "u1hippo-35", "created_on": ISODate("2017-01-05T01:16:01.000Z") },{ "_id": ObjectId("595baefce2810a6a8a94fe45"), "user": "u1", "type": "session_started", "name": "my session_started", "reference_id": "u1hippo-36", "created_on": ISODate("2017-01-05T01:17:01.000Z") },{ "_id": ObjectId("595baefce2810a6a8a94fe46"), "user": "u1", "type": "session_skipped", "name": "my session_skipped", "reference_id": "u1hippo-36", "created_on": ISODate("2017-01-06T01:18:01.000Z") },{ "_id": ObjectId("595baefce2810a6a8a94fe47"), "user": "u1", "type": "session_started", "name": "my session_started", "reference_id": "u1hippo-37", "created_on": ISODate("2017-01-07T01:19:01.000Z") },{ "_id": ObjectId("595baefce2810a6a8a94fe48"), "user": "u1", "type": "session_completed", "name": "my session_completed", "reference_id": "u1hippo-37", "created_on": ISODate("2017-01-07T01:20:01.000Z") },{ "_id": ObjectId("595baefce2810a6a8a94fe49"), "user": "u1", "type": "session_started", "name": "my session_started", "reference_id": "u1hippo-38", "created_on": ISODate("2017-01-09T01:21:01.000Z") },{ "_id": ObjectId("595baefce2810a6a8a94fe4a"), "user": "u1", "type": "session_completed", "name": "my session_completed", "reference_id": "u1hippo-38", "created_on": ISODate("2017-01-09T01:21:01.000Z") }]);