Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to convert from activequery to json query #358

Open
donny26utama opened this issue Jun 12, 2023 · 3 comments
Open

How to convert from activequery to json query #358

donny26utama opened this issue Jun 12, 2023 · 3 comments

Comments

@donny26utama
Copy link

donny26utama commented Jun 12, 2023

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
@donny26utama donny26utama changed the title How to return from activequery to json query How to convert from activequery to json query Jun 12, 2023
@ziaratban
Copy link
Contributor

Hi

$book = Book::find()->where(['status' => 'publish'])->one();

Please see https://www.yiiframework.com/doc/api/2.0/yii-db-queryinterface#where()-detail

@donny26utama
Copy link
Author

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"}

@ivanflashacademy
Copy link

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 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants