top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How can i use if condition in mongodb using php?

0 votes
451 views
How can i use if condition in mongodb using php?
posted Nov 24, 2016 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Here is an example which I have used with mongo-php driver

$collection=$database->collectionName;
$uniqueVariable=$collection->find($StudentName);
if(count($uniqueVariable)==1)
{
 echo "Result set is already present with given student name";
}
answer Dec 4, 2016 by Shivam Kumar Pandey
Similar Questions
+2 votes

I am new to mongodb but I know php so I want to implement both and develop a single page application using php and mongoDB.A sample code will be helpful for me like.CRUD Operation

+3 votes

I am very new to mongodb, my requirement is need to search a value in two fields. ex: first_name, last_name

I am using PHP as serverside and mongodb as backend.

Can you please suggest, How can I write the query in PHP.

Below is the things, I tried to implement but not succeeded.

db.users.aggregate(
  [
  { $project: { userName: { $concat: [ "$first_name", " - ", "$last_name" ] } } }
  ]
)
+1 vote

I recently upgraded the latest PHP driver and could do an "explain" query by using the "$explain" modifier when executing the query, however as of MongoDB 3.2 the operator was removed so this is no longer possible.

So my question is how can I do an explain query with the new driver and MongoDB 3.2?

...