yii2-mongodb
yii2-mongodb copied to clipboard
How to convert from activequery to json query
What steps will reproduce the problem?
$book = Book::find()->where(['=', 'status'. 'publish')->rawQuery();
What's expected?
db.getCollection("book").find({
"status": "publish"
});
What do you get instead?
Additional info
Q | A |
---|---|
Yii version | 2.0.14 |
Yii MongoDB version | 2.1 |
MongoDB server version | 5.0.6-5 |
PHP version | 7.4 |
Operating system | windows |
Hi
$book = Book::find()->where(['status' => 'publish'])->one();
Please see https://www.yiiframework.com/doc/api/2.0/yii-db-queryinterface#where()-detail
Hi
$book = Book::find()->where(['status' => 'publish'])->one();
Please see https://www.yiiframework.com/doc/api/2.0/yii-db-queryinterface#where()-detail
I think you misunderstand my question, my question is how to get a raw query from ActiveQuery
,
if you use a relational database like MySQL
when $book = Book::find()->where(['status' => 'publish'])->getRawSql();
you will get SELECT * FROM books WHERE status = 'publish'
. So, when I use NoSQL
like MongoDB, my expectation is something like db.getCollection("book").find({ "status": "publish" });
or only JSON {"status": "publish"}
I will be appreciate you to add this feature Sometimes it is great to check native query in db client and make sure that your query is correct Thanks :+1:
Another alternative is to use MongoDB Debug Panel which will show us additional information for each command / query.
In OP's case, it will show the query like so:
log.command({"count":"book","query":{"$and":[{"$and":[{"status",.....