Mongo make an array with date as key ?
[_id] => MongoId Object (
[$id] => 4fcf2f2313cfcd225700000d
)
[id] => 14
[name] => Aryan Roban
[news] => Array (
[08-06-2012] => 12
)
Here I want a make news as array with date as key and how to delete a particular key row ?
For example
I want to delete array element with key ’08-06-2012′ in news array , I dont know the value of it.
Finding Documents won’t be a problem, this is very easy. Simply look if
newshas got a key which matches your search criteria:Don’t forget to put an index on
news.But deleting them is not easily possible. There is another thread which show shows a way to do that, but it’s really rather a workaround: In mongoDb, how do you remove an array element by its index Sadly this only works for arrays with numerical indexes and not for associative arrays.
Maybe you could use an own collection for news? Then you could update and delete them easily. Otherwise you could load a full document from your database, manipulate the news in your application and save it afterwards. This would require two datebase queries, but should work.