Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I run explain on MongoDB update?

Tags:

mongodb

I'm trying to explain a mongoDB update; but nothing is happening? Does Mongo not support this?

> db.movies.update({"actors.name": "Christian Bale"}, {$set: {"actors.$.name": "Christina Bale"}}, {$explain: 1});
>

I've tried other variations using .explain() and ._addSpecial("$explain", 1"). Both of these produce the following error:

Thu Aug 1 11:26:46.368 JavaScript execution failed: TypeError: Cannot call method 'explain' of undefined

like image 337
Logan Bailey Avatar asked Aug 01 '13 18:08

Logan Bailey


2 Answers

I believe the following will allow you to call explain on your query.

    db.movies.explain().update({your_query})

Hope this helps, if you need more info let me know.

like image 200
Hughzi Avatar answered Sep 19 '22 23:09

Hughzi


Why do you want to call explain on update? AFAIK, explain will show you how your query will fetch the rows, so you could simply do:

db.movies.find(
    {$query:  {"actors.name": "Christian Bale"}},
    {$explain: 1}
);
like image 41
Roman Pekar Avatar answered Sep 20 '22 23:09

Roman Pekar