I’m using MongoDB with PHP to store songs which users add via a basic form. The collection I created looks like below.
$object = array(
"trackName" => "Sju sorger",
"artistName" => "Veronica Maggio",
"albumName" => "Satan i Gatan",
);
$collection->save($object);
What I trying to accomplish is to check if a song is already in the collection. If the song user trying to add is not already in the collection, it’d be added. If it is already in the collection, a notification stating that the song is already in the collection will be displayed.
I’m relatively new to MongoDB but I assume I can check if the song is already in the collection by checking the _id of the document. But I have no idea on how to accomplish that.
Any help would be much appreciated.
Use this approach.
use this resource for further.
Mongo Resource