If possible please give me mongo query for below sql queries.
Ex:
1. select table1.id from table1 where table1.id in (select table2.id from table2 where table2.status='active')
2. select t1.id from table1 t1,table 2 t2 where t1.id=t2.id and t2.status='active'
i don't think so join is possible in mongodb, but you can write some queries in repository.. you are using mongodb with which technology, that's any framework or what technology.
$qb = $this->createQueryBuilder(' ProductRegister');
$qb->addOr($qb->expr()->field( 'productName')->equals(new \MongoRegex('/.*' . $productName . '.*/')));
$qb->addOr($qb->expr()->field( 'productLIne')->equals(new \MongoRegex('/.*' . $productName . '.*/')));
$qb->sort('productName', 'ASC');
$qry = $qb->getQuery();
$query = $qry->execute();
return $query;
Thanks for reply,
I am using Aggregation framework.
Ex code:
$query = array('$or'=> array(array("userid"=>"1234"))
//$query = array('$or'=> array(array("mid"=>"$mid"),
$collections= $mongo->table->find($query)->
foreach($collections as $row){
$name=$row['name'];
}
Can I add two tables same like this way?
I am using MongoDb with Core PHP.
No, you cannot use inner joins or any joins, since MongoDB is not a
relational database and does not support joins.
If you have to query two tables then you will have to make two separate queries.
MongoDB doesn’t support subquery and join, you should first retrieve the data before any further computation can be performed.
But for this purpose, programming languages like Java and Php should be used to write the program and the code will be complicated. Try using esProc in this case.
It is specially designed for structured data computing and the code written with it is more concise than that written with Java or Php. For concrete examples, please refer to http://blog.raqsoft.com/?p= 1591.
esProc also provides a JDBC interface, though which the access of an esProc program is almost the same as that of a database.
댓글 없음:
댓글 쓰기