V
V
Victoria2016-04-03 08:01:43
PHP
Victoria, 2016-04-03 08:01:43

How to add data to MongoDB in php?

I'm familiar with MongoDB. I found examples of working in php with Mongo, I'm trying to write a method for adding data to the database:

//класс для работы с MongoDB
class Database {

public function save($data){
    $m = new MongoClient();
    $m -> selectDB(DB_NAME) -> selectCollection(COLLECTION_NAME);
    $m -> insert($data);
    $m -> close();
}
}

Error on the insert() method. Php doesn't see it. I can’t understand why, I follow the example from here: metanit.com/nosql/mongodb/3.3.php

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey, 2016-04-03
@VladimirAndreev

insert is a MongoCollection method, not MongoClient

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question