Assume that we have a MongoDB server installed as a windows service on the same machine as our web server. The server listens on port 33333.
We met a new friend, and we want to save some details about her. That night, before bidding farewell, she said: “Remember me, I am Mary Jane. You can write to me at mary.jane@gmail.com“.
Although that’s all we have about her, this is sufficient for us to insert a document about Mary into our MongoDB database.
Inserting documents into collections in MongoDB with PHP consists of the following steps:
- Derive an instance of the
MongoCollection
class that represents the MongoDB collection to insert documents.
- Define the document to insert.
- Define additional options for the insert.
- Execute the insert function of the
MongoCollection
instance.
Follow us