Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7908249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:51:03+00:00 2026-06-03T11:51:03+00:00

I using MongoId reading through the given answer for the question I understood Mongoid

  • 0

I using MongoId reading through the given answer for the question I understood Mongoid

does not cache any query

Now when running the below query

PartPriceRecord.destroy_all

PartPriceRecord.count()
==> 31721

How that is possible i just delete all the record ,this get me a feel mongo is caching certain query

In my mongoid query log I can see for every delete two query operating

MONGODB (0ms) decisiv_staging['system.indexes'].insert([{:name=>"part_number_1", :ns=>"decisiv_staging.part_price_records", :key=>{"part_number"=>1}, :unique=>true}])
MONGODB (0ms) decisiv_staging['part_price_records'].remove({:_id=>BSON::ObjectId('4fa39b35edd7f4306b0042bf')})

Signify that index are created and record is getting removed.

so how come mongo is caching the query is there any way from mongoid to clear mongo cache
If mongo is caching the query

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T11:51:10+00:00Added an answer on June 3, 2026 at 11:51 am

    Caveat: I am not a mongoid user.

    so how come mongo is caching the query

    Mongo itself doesn’t do any caching like that.

    If you look at the queries executed on the db:

    $ mongodb viren
    > db.setProfilingLevel(0); 
    > db.system.profile.drop();  
    > db.setProfilingLevel(2);
    

    Then execute your code, you’ll see something like this in the log:

    > db.system.profile.find()
    { "ts" : ISODate("2012-05-09T08:39:21.657Z"), "op" : "insert", "ns" : "viren.part_price_records", "millis" : 0, "client" : "127.0.0.1", "user" : "" }
    { "ts" : ISODate("2012-05-09T08:39:26.553Z"), "op" : "remove", "ns" : "viern.part_price_records", "query" : { }, "millis" : 0, "client" : "127.0.0.1", "user" : "" }
    

    Looking directly at the db will allow you to know/understand exactly what queries are issued and if there is caching – where it is (it won’t be in the db itself).

    However, the big difference above to the query log you’ve shown in the question is that .remove({:_id=>BSON::ObjectId('4fa39b35edd7f4306b0042bf')}) will remove at most one object, the conditions above ({}) will truncate the collection.

    Looking at the docs for destroy all, it runs callbacks on each deleted row – which probably means it deletes them one at a time (which with 30k rows will take a significant time). You can use delete all and it will (I assume) directly issue a query to delete all rows (db.part_price_records.remove({})) instead. If you need destroy callbacks, you need to investigate why your code apparently only finds one row to delete, or which callback is aborting the delete for the other existing rows.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Mongoid. Unfortunately, Mongoid does not allow for selecting unique / distinct! Have gotten
I would like to write a query in a Rails model using mongoid, and
Is there any one command in Mongoid to delete an object using id? Something
I was writing a Blog like application Using Rails3/Mongoid, and now trying to use
I have a Rails 3.1 app, running on Ruby 1.9.2, Mongo 2.0.2, using Mongoid
Really not much more to tell than what is already in the question. using
I'm using mongoid , machinist 2 and pickle . But I think, that question
I`m having a problem with search query in Rails 3 application using Mongoid. My
I can't seem to find anything to make a date range query using Mongoid/Rails.
Is there any way to ensure geo hash order using mongoid? Currently I store

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.