On Thu, 12 Mar 2015, sanjay mangalaram wrote:
> I have checked mongodb commands which insert the data in json format.
> that's works when we try this using terminal:
> db.adddata.insert(
>
> {
> item: "BE10",
> details: { model: "14Q2", manufacturer: "XYZ Company"},
> stock: [ { size: "L", qty: 5}],
> category: "clothing"
>
> });
>
> While I am doing the same using PHP code to insert json format data it gives error like
> *Warning*: MongoCollection::insert(): expects parameter 1 to be an array or object, string given in
This list is for the development *of* MongoDB, not for people using
MongoDB. Please use the
mongod...@googlegroups.com group for future
questions.
In any case, you need to use the language's native data formats
for storing data into MongoDB.
In PHP, that would be like:
$db->colname->insert( [
'item' => 'BE10',
'details' => [ 'model' => '14q2', 'manufacturer' => 'XYZ Company' ],
'stock' => [ [ 'size' => 'L', 'qty' => 5 ] ],
'category' => 'clothing'
] );
Which probably means, you might need to convert your JSON string to PHP
data types, with the json_decode() function.
cheers,
Derick