mongofill / mongofill-hhvm

A mix of the original Mongofill extension + BSON implementation in C++
MIT License
32 stars 19 forks source link

Accept non-referenced objects in insert #41

Closed steelbrain closed 9 years ago

steelbrain commented 9 years ago

It's annoying and painful to store your objects in variables prior to executing insert in them. Here's the error message.

Fatal error: Cannot pass parameter 1 by reference in /path/to/file.hh on line 59

It disallows inserts like

$collection->insert(array('some' => 'thing'))

Here's the workaround

$hurts = array('like' => 'hell');
$collection->insert($hurts);

I believe you have something like this in your codebase that's causing it

function insert(&$toInsert){}

just remove that & and I'll be happy as in pie.

mcuadros commented 9 years ago

the behaviour of the original driver cannot be replicated because you cannot accept values by reference and also values.

sorry :( you must use the workaround.

steelbrain commented 9 years ago

Quite sad :( I have read the conversations and found out that the reference is there because the mongofill driver inserts the _id into the object. I solved it by generating a MongoId myself and giving it to mongofill and editing the source of it and removing that function that inserts it and the & that was causing the problem. That works fine for me, Thanks :)

ChrisFrench commented 8 years ago

@steelbrain can you give me more infomation about this? I have ran into the same issue

steelbrain commented 8 years ago

@ChrisFrench This is more of a runtime limitation and the fact that this package requires references, the problem and the workaround are in the first post. The long-time solution for me was to fork this package and remove the reference requirement in most of the public methods

ChrisFrench commented 8 years ago

@steelbrain ahh funny I actually thought of doing the same. I have a whole suite of tools that can use mongo, and I was trying to use this as a fall back so it could run on cheap hosting.

Do you have that fork around by chance?

steelbrain commented 8 years ago

@ChrisFrench This is my fork https://github.com/ZoomPK/mongofill I would advise you read my commits before using so you know what it does differently