chris.chen21
2011-09-25 02:32:28 UTC
Schema looks something like this:
{_id: ... , aliases: [...]}
The index:
db.songs.ensureIndex({"aliases":1},{'unique':true});
When running a query like this:
$col->update(
{ '_id' => '123' , 'aliases'=>'fat tony'},
{
'$addToSet' => { 'aliases' => 'fat tony' },
},
{ 'upsert' => 1, }
);
I get
Cannot apply $addToSet modifier to non-array
Is there a way to tell mongodb in the upsert query that 'aliases'
should be an array containing 'fat tony' if it doesn't exist?
{_id: ... , aliases: [...]}
The index:
db.songs.ensureIndex({"aliases":1},{'unique':true});
When running a query like this:
$col->update(
{ '_id' => '123' , 'aliases'=>'fat tony'},
{
'$addToSet' => { 'aliases' => 'fat tony' },
},
{ 'upsert' => 1, }
);
I get
Cannot apply $addToSet modifier to non-array
Is there a way to tell mongodb in the upsert query that 'aliases'
should be an array containing 'fat tony' if it doesn't exist?